Cod sursa(job #988758)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 23 august 2013 19:47:59
Problema Subsir crescator maximal Scor 65
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <cstdio>
#define FOR(i,a,b) for(int i= (a) ; i <= (b); ++i)
#define Nmax 100666
int D[ Nmax ],L[ Nmax ],best[ Nmax ],n,nrb=1;
void update(int poz)
{
    int li = 1,lf = nrb,m;
    while(li <= lf){
        m = li + (lf - li) / 2;
        if( best[m] < D[poz] ) li = m + 1;
        else if(best[m] >= D[poz])lf = m - 1;
    }
    if(lf + 1 > nrb)++nrb;
    best[lf + 1] = best[lf + 1] < D[poz] ? best[lf + 1] : D[poz];
    L[poz] = lf + 1;
}

int main()
{
    freopen("scmax.in","r",stdin);
    freopen("scmax.out","w",stdout);
    scanf("%d\n",&n);
    FOR(i,1,n){
        scanf("%d",&D[ i ]);
        best[ i ] = 2000000666;
        update(i);
    }
    printf("%d\n",nrb);
    FOR(i,1,nrb)printf("%d ",best[i]);
    return 0;
}