Cod sursa(job #2651383)

Utilizator Snake2003lalallalal Snake2003 Data 22 septembrie 2020 15:09:18
Problema Subsir crescator maximal Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

int sclm[1005], k;

int main()
{
    int nr;
    fin >> nr;
    int x;
    fin >> x;
    sclm[++ k] = x;
    for(int i = 2; i <= nr; i ++)
    {
        int y;
        fin >> y;
        if(y > sclm[k])
            sclm[++ k] = y;
        else
        {
            int upper = upper_bound(sclm + 1, sclm + k + 1, y) - sclm;
            sclm[upper] = y;
        }
    }
    fout << k << "\n";
    for(int i = 1; i <= k; i ++)
        fout << sclm[i] << " ";
    return 0;
}