Cod sursa(job #1546803)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 8 decembrie 2015 18:58:55
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;

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

int a[100001], n;
int len[100001], father[100001];

void baga(int poz)
{
    if( poz == 0 )
        return;
    baga(father[poz]);
    fout << a[poz] << ' ';
}

int main()
{
    fin >> n;
    int lmax = 0, pmax, l, p;
    for( int i = 1; i <= n; ++i )
    {
        fin >> a[i];
        l = 0, p = 0;
        for( int j = i - 1; j > 0; --j )
        {
            if( a[j] < a[i] && len[j] > l )
                l = len[j], p = j;
        }
        len[i] = l + 1;
        father[i] = p;
        if( len[i] > lmax )
            lmax = len[i], pmax = i;
    }
    fout << lmax << '\n';
    baga(pmax);
    return 0;
}