Cod sursa(job #2630647)

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

int main () {
    ifstream fin ("scmax.in");
    ofstream fout ("scmax.out");
    vector <int> deck;

    int n, x;
    fin >> n;
    for (; n; n--) {
        fin >> x;
        auto it=upper_bound(deck.begin(), deck.end(), x-1);
        if (it==deck.end())
            deck.push_back(x);
        else
            *it=x;
    }

    fout << deck.size() << endl;
    copy(deck.begin(), deck.end(), ostream_iterator <int> (fout, " "));
    return 0;
}