Pagini recente » Painting | Monitorul de evaluare | Rating Filipciuc Andreea (Filipciuc) | Cod sursa (job #2236306) | Cod sursa (job #177375)
Cod sursa(job #177375)
#include<cstdio>
int a[100001],i,x,nr,n,best[100001],last[100001],list[100001],max;
inline int poz(int x)
{
int st=0,dr=nr,m;
while(st<dr)
{
m=(st+dr+1)>>1;
if(a[list[m]]==x) return m-1;
if(a[list[m]]<x) st=m;
else dr=m-1;
}
return st;
}
inline void sol(int i)
{
if(i==0) return;
sol(last[i]);
printf("%d ",a[i]);
}
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]);
x=poz(a[i]);
list[x+1]=i;
if(x+1>nr) nr=x+1;
best[i]=x+1;
last[i]=list[x];
if(best[i]>best[max]) max=i;
}
printf("%d\n",best[max]);
sol(max);
fclose(stdout);
return 0;
}