Pagini recente » Cod sursa (job #1312096) | Cod sursa (job #2004196) | Cod sursa (job #2287288) | Cod sursa (job #2825914) | Cod sursa (job #744740)
Cod sursa(job #744740)
#include<cstdio>
using namespace std;
int L,a[100000],q[100000],p[100000],i,n,max,k;
int bin(int x,int st,int dr){
int m,poz;
poz=0;
while (st<=dr && poz==0){
m=(st+dr)/2;
if (q[m]==x) poz=m;
else if (q[m]>x) dr = m-1;
else st = m+1;
}
if (poz==0) poz=st;
if (st>L) L++;
q[poz]=x;
return poz;
}
void scrie ( int i, int x, int max){
if(i>0){
if (a[i]<x && p[i]==max) {
scrie (i-1, a[i], max-1);
printf("%d ", a[i]);
}
else scrie (i-1, x, max);
}
}
int main(){
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
for(i=1;i<=n;i++){
p[i]=bin(a[i],1,L);
if(p[i]>max){
max=p[i];
k=i;}}
printf("%d\n",L);
scrie(k,2000000001,max);
return 0;
}