Cod sursa(job #2748838)

Utilizator StasBrega Stanislav Stas Data 3 mai 2021 16:54:53
Problema Subsir crescator maximal Scor 65
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

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

int main()
{
    
    int n; fin >> n;
    
    vector<long long> ans;
    
    while(n--) {
        long long x; fin >> x;
        auto poz = lower_bound(ans.begin(), ans.end(), x);
        if(poz == ans.end())
            ans.push_back(x);
        else
            ans[poz - ans.begin()] = x;
    }
    
    fout << ans.size() << '\n';
    for(int x: ans)
        fout << x << ' ';

    return 0;
    
}