Pagini recente » Cod sursa (job #1025296) | Cod sursa (job #2000574) | Cod sursa (job #1365553) | Cod sursa (job #2108748) | Cod sursa (job #3152207)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
const int NMAX = 1e5;
const int INF = 2e9+1e4;
int n;
int v[NMAX+1], best[NMAX+1], prevv[NMAX+1];
int cb(int val){
int st = 1;
int dr = n;
int rez = 0;
while(st <= dr){
int mij = (st+dr)/2;
if(best[mij] != 2e9+1e4 and v[best[mij]] < val)
rez = mij, st = mij+1;
else dr = mij-1;
}
return rez;
}
int main()
{
f >> n;
for(int i=1; i<=n; i++)
f >> v[i];
fill(best, best+1+NMAX, 2e9+1e4);
for(int i=1; i<=n; i++){
int poz = cb(v[i]);
prevv[i] = best[poz];
best[poz+1] = i;
}
int last = 0;
int sz = 0;
for(int i=1; i<=n; i++)
if(best[i] != 2e9+1e4)
sz = i, last = best[i];
g << sz << endl;
while(last != INF){
g << v[last] << ' ';
last = prevv[last];
}
return 0;
}