Cod sursa(job #1410398)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 31 martie 2015 01:01:55
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include<cstdio>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<unordered_map>

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

using namespace std;

const int nmax = 100005;
const int inf = (1LL << 31) - 1;

int n, i, poz, lis, mlc, sol[nmax], a[nmax], v[nmax], where[nmax];

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

    scanf("%d", &n);

    for(i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        v[i] = inf;
        poz = lower_bound(v + 1, v + i + 1, a[i]) - v;
        v[poz] = a[i];
        where[i] = poz;
        lis = max(lis, poz);
    }

    for(i = n; i; i--)
        if(where[i] == lis)
            sol[++mlc] = a[i], lis--;

    printf("%d\n", mlc);
    for(i = mlc; i; i--)
        printf("%d ", sol[i]);

    return 0;
}