Cod sursa(job #2631858)

Utilizator Snake2003lalallalal Snake2003 Data 1 iulie 2020 13:41:04
Problema Subsir crescator maximal Scor 15
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <bits/stdc++.h>
using namespace std;

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

int n, i, x, v[1];
unsigned long long sclm[100001], fr[100001];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    fin >> n;
    fin >> v[1];
    int k = 1;
    sclm[k] = v[1];
    fr[v[1]] = 1;
    for(int i = 2; i <= n; i ++)
    {
        fin >> x;
        if(fr[x] != 0)
            continue;
        else if(x > sclm[k] && fr[x] == 0)
        {
            sclm[++ k] = x;
            fr[x] = 1;
        }
        else if(x < sclm[k] && fr[x] == 0){
            int upper = upper_bound(sclm + 1, sclm + k + 1, x) - sclm;
            sclm[upper] = x;
            fr[x] = 1;
        }
    }
    fout << k << "\n";
    for(int i = 1; i <= k; i ++)
        fout << sclm[i] << " ";
    return 0;
}