Mai intai trebuie sa te autentifici.
Cod sursa(job #883982)
Utilizator | Data | 20 februarie 2013 16:26:45 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 45 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.64 kb |
#include<cstdio>
#include<algorithm>
#define oo (1<<31)-1
#define NMAX 100000+5
using namespace std;
int a[NMAX],t[NMAX],p[NMAX],i,j,n,sol,x;
void write(int x)
{
if(p[x]==0) {printf("%d ",a[x]); return;}
write(p[x]);
printf("%d ",a[x]);
}
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]);
t[i]=oo;
j=(int)(lower_bound(t+1,t+i+1,a[i])-t);
t[j]=a[i];
p[i]=(j==1)?0:j;
sol=max(sol,j);
if(sol==j) x=i;
}
printf("%d\n",sol);
write(x);
return 0;
}