Cod sursa(job #2591205)

Utilizator k2e0e0w3qDumitrescu Gheorghe k2e0e0w3q Data 29 martie 2020 23:40:53
Problema Subsir crescator maximal Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;

ofstream fout ("scmax.out");
int *v, *link;
void print (int poz) {
    if (poz!=-1) {
        print(link[poz]);
        fout << v[poz] << ' ';
    }
}

int main () {
    ifstream fin ("scmax.in");
    ios::sync_with_stdio(false);

    vector <int> deck;
    int n, i, last;
    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]=i-1, last=i;
        else
            *it=v[i], link[i]=it-deck.begin();
    }

    fout << deck.size() << '\n';
    print(last);
    return 0;
}