Cod sursa(job #2098580)

Utilizator AndreiTurcasTurcas Andrei AndreiTurcas Data 3 ianuarie 2018 02:14:40
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
#define mx 100005
using namespace std;

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

int v[mx], d[mx], t[mx], n, Lm, k;

void Subseq(int x)
{
    if(x != 0)
    {
        Subseq(t[x]);
        g << v[x] << " ";
    }
}

int main()
{
    d[1] = 1; k = 1;
    f >> n;
    for(int i = 1; i <= n; ++i)
        f >> v[i];
    for(int i = 2; i <= n; ++i)
    {
        int st = 1, dr = k;
        while(st <= dr)
        {
            int mj = (st+dr)/2;
            if(v[d[mj]] < v[i]) st = mj+1;
            else dr = mj-1;
        }
        if(st > k) k++;
        d[st] = i;
        t[i] = d[st-1];
    }
    g << k << "\n";
    Subseq(d[k]);
}