Cod sursa(job #2909729)

Utilizator TheGarbageWeebIonescu Ioan-Andrei TheGarbageWeeb Data 14 iunie 2022 23:05:54
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>

using namespace std;

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

int v[100005], s[100005], lu[100005], t[100005], n, lmax, i, j, m;

int main()
{
    in >> n;
    for (i = 0; i < n; i++)
    {
        in >> v[i];
        j = 1;
        while (s[j] < v[i] && j <= lmax)
            j++;
        s[j] = v[i];
        lu[i] = j;
        if (j > lmax)
            lmax = j;
    }

    out << lmax << '\n';
    m = lmax;
    for (i = n; i >= 0; i--)
    {
        if (lu[i] == lmax)
            t[lmax--] = v[i];
    }
    for (i = 1; i <= m; i++)
        out << t[i] << " ";

   return 0;
}