Pagini recente » Cod sursa (job #1465738) | Cod sursa (job #1630508) | Cod sursa (job #3288444) | Cod sursa (job #1028403) | Cod sursa (job #1979027)
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
#define pb push_back
#define ll long long
const int NMax = 1e5 + 5;
int N,nrSol;
int v[NMax],sol[NMax],pre[NMax];
void print(int);
int main() {
in>>N;
nrSol = 0;
for (int i=1;i <= N;++i) {
in>>v[i];
int pos = 0,pw;
for (pw = 1;pw <= nrSol;pw <<= 1) ;
pw >>= 1;
while (pw) {
if (pos + pw <= nrSol && v[sol[pos + pw]] <= v[i]) {
pos += pw;
}
pw >>= 1;
}
if (v[sol[pos]] == v[i]) {
continue;
}
sol[pos+1] = i;
pre[i] = sol[pos];
if (pos == nrSol) {
++nrSol;
}
}
out<<nrSol<<'\n';
print(sol[nrSol]);
in.close();
out.close();
return 0;
}
void print(int x) {
if (x == 0) {
return;
}
print(pre[x]);
out<<v[x]<<' ';
}