Cod sursa(job #2630654)

Utilizator doyouhavethetimeStanculescu Gabriel doyouhavethetime Data 26 iunie 2020 16:31:07
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;

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

int *v, *link;
void show (int poz) {
    if (poz!=-1) {
        show(link[poz]);
        fout << v[poz] << ' ';
    }
}
int main () {
    vector <int> deck, pos;
    pos.push_back(-1);

    int n, i;
    fin >> n;
    v=new int[n], link=new int[n];

    for (i=0; i<n; i++) {
        fin >> v[i];
        auto it=upper_bound(deck.begin(), deck.end(), v[i]-1);
        if (it==deck.end())
            deck.push_back(v[i]),
            link[i]=pos.back(),
            pos.push_back(i);
        else
            *it=v[i],
            pos[it-deck.begin()+1]=i,
            link[i]=pos[it-deck.begin()];
    }

    fout << deck.size() << '\n';
    show(pos.back());
    return 0;
}