Cod sursa(job #1686112)

Utilizator AlexandruX1Ureche Florin Alexandru AlexandruX1 Data 12 aprilie 2016 08:23:05
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NR = 100000;
int a[NR], l[NR], t[NR], n, f, Lmax;

void Rec (int ind)
{
    if (ind == 0) return;
    Rec (t[ind]);

    fout << a[ind] <<" ";

}

int main()
{
    fin >> n;
    for (int i = 1; i <= n; i ++) {fin >> a[i]; l[i] = 1;}

    for (int i = 1; i <= n; i ++)
    {
    for (int j = 1; j < i; j ++)
    if (l[j] >= l[i] && a[j] < a[i])
        {
            l[i] = l[j] + 1;
            t[i] = j;
        }

    if (Lmax < l[i])
    {
        Lmax = l[i];
        f = i;
    }
    }

    fout << Lmax <<"\n";
    Rec(f);

    return 0;
}