Pagini recente » Cod sursa (job #2338053) | Cod sursa (job #301830) | Cod sursa (job #967893) | Cod sursa (job #13658) | Cod sursa (job #744772)
Cod sursa(job #744772)
#include <cstdio>
#define inf 2000000001
using namespace std;
int l,poz,poz2,i,j,n,max,a[100000],p[100000],q[100000];
int cautare(int x,int st,int dr)
{
int m;
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;
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);max=0;l=0;
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;++i){p[i]=cautare(a[i],1,max);if(p[i]>max) {max=p[i];poz2=i;}}
printf("%d\n",max);
scrie(poz2,inf,max);
return 0;
}