Cod sursa(job #1199190)

Utilizator lorundlorund lorund Data 18 iunie 2014 15:41:15
Problema Subsir crescator maximal Scor 65
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <cstdio>
#define SIZE 100005

int N, x;
int lmax, best[SIZE];

int main()
{
    freopen("scmax.in", "r", stdin);
    freopen("scmax.out", "w", stdout);

    scanf("%d", &N);
    for (int i=0; i<N; ++i){
        int x, li=1, ls=lmax;
        scanf("%d", &x);

        while (li<=ls){
            int m=(li+ls)/2;

            if (best[m]>=x)
                ls = m-1;
            else
                li = m+1;
        }
        if (!best[li]){
            ++lmax;
        }
        best[li] = x;
    }
    printf("%d\n", lmax);
    for (int i=1; i<=lmax; ++i)
        printf("%d ", best[i]);
    return 0;
}