Cod sursa(job #1053180)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 12 decembrie 2013 14:55:06
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include<cstdio>
#include<algorithm>
using namespace std;
const int NMAX = 100005;
const int INF = (1<<31)-1;
int N,V[NMAX],Q[NMAX],P[NMAX],S[NMAX],Poz,i,SOL;
int main()
{
    freopen("scmax.in","r",stdin);
    freopen("scmax.out","w",stdout);
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%d",&V[i]); Q[i]=INF;
        Poz=lower_bound(Q+1,Q+i+1,V[i])-Q;
        Q[Poz]=V[i]; P[i]=Poz;
        SOL=max(SOL,Poz);
    }
    for(Poz=SOL,i=N;i && Poz;i--)
        if(P[i]==Poz) S[Poz--]=V[i];
    printf("%d\n",SOL);
    for(i=1;i<=SOL;i++) printf("%d ",S[i]);
    return 0;
}