Cod sursa(job #1111007)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 18 februarie 2014 16:18:54
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#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;
}