Cod sursa(job #1502403)

Utilizator doroftei1999Doroftei Andrei doroftei1999 Data 14 octombrie 2015 17:02:38
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[100001], i, n, j, best[100001], poz[100001], p, Max;
void citire()
{
    f >> n;
    for (i = 1; i <= n; i++)
        f >> v[i];
}
void maxim()
{
    best[n] = 1;
    poz[n] = - 1;
    for (i = n - 1;i >= 1; i--){
        best[i] = 1;
        poz[i] = - 1;
        for (j = i + 1; j <= n; j++){
            if (v[i] < v[j] && best[i] < best[j] + 1){
                best[i] = best[j] + 1;
                poz[i] = j;
            }
        }
        if (best[i] > Max){
            Max = best[i];
            p = i;
        }
    }
}
int main()
{
    citire();
    maxim();
    g<<best[p]<<'\n';
    i = p + 1;
    while (p != -1){
        g << v[p] << ' ';
        p = poz[p];
    }
    return 0;
}