Cod sursa(job #2386056)

Utilizator oogaboogauvuvwevwevwe onyetenyevwe ugwemubwem ossas oogabooga Data 22 martie 2019 09:16:48
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("scmax.in");
ofstream out("scmax.out");

const int MX = 100005;

int n, lg;
int v[MX], a[MX], pz[MX];

int main()
{
    in>>n;
    for(int i = 1; i <= n; ++i) in>>v[i];

    a[++lg] = v[1];

    for(int i = 2; i <= n; ++i)
        if(v[i] > a[lg])
            a[++lg] = v[i], pz[i] = lg;
        else
        {
            int p = lower_bound(a + 1, a + lg + 1, v[i]) - a;
            a[p] = v[i];
            pz[i] = p;
        }

    int t = lg;

    for(int i = n; i >= 1; --i)
        if(pz[i] == t)
        {
            a[t] = v[i];
            --t;
        }

    out<<lg<<"\n";
    for(int i = 1; i <= lg; ++i)
        out<<a[i]<<" ";

    return 0;
}