Pagini recente » Cod sursa (job #2279293) | Monitorul de evaluare | Autentificare | Cod sursa (job #2967526) | Cod sursa (job #1111007)
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF = (1<<31)-1;
const int NMAX = 100000+5;
int N,best;
int V[NMAX];
int T[NMAX];
int P[NMAX];
int main()
{
int i,j;
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&N);
for(i=1; i<=N; i++)
{
scanf("%d",&V[i]);
T[i]=INF;
j=lower_bound(T+1,T+i+1,V[i])-T;
T[j]=V[i];
P[i]=j;
best=max(best,j);
}
for(j=best,i=N; i && j; --i)
if(P[i]==j)
{
T[j]=V[i];
j--;
}
printf("%d\n",best);
for(i=1; i<=best; i++)
printf("%d ",T[i]);
return 0;
}