Pagini recente » Cod sursa (job #2754190) | Cod sursa (job #2092314) | Cod sursa (job #184074) | Cod sursa (job #2138044) | Cod sursa (job #2255424)
#include <fstream>
#include <map>
#include <iostream>
#define nMax 100005
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int main()
{
int n, i, lmax = 0, l, pos;
int v[nMax] = {0}, prev[nMax] = {0}, _end[nMax] = {0}, aux[nMax] = {0};
map<int, int> m; map<int, int>::iterator it;
fin >> n; for(i = 1; i <= n; i++) fin >> v[i];
for(i = 1; i <= n; i++){
it = m.lower_bound(v[i]);
if(it != m.end()){
pos = ((*it).second);
m.erase(it);m.insert(make_pair(v[i], pos));
}
else{
pos = ++lmax;
m.insert(make_pair(v[i], pos));
}
_end[pos] = i; prev[i] = _end[pos - 1];
}
l = 0;
for(pos = _end[lmax]; pos != 0; pos = prev[pos]) _end[++l] = v[pos];
fout << lmax << "\n"; for(i = lmax; i >0; i--) fout << _end[i] << " ";
return 0;
}