Cod sursa(job #1502389)

Utilizator istrate.cristianIstrate Cristian istrate.cristian Data 14 octombrie 2015 16:53:19
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;

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

int v[100005], poz[100005], best[100005];

int main()
{
    int n , j, i, Max=0,p;
    f>>n;
    for(i=1;i<=n;i++)
        f>>v[i];
    best[n]=1;
    poz[n] =-1;
    for(i=n-1 ; i>0 ;i--){
        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;
            }
    }
    g << Max << '\n';
    while(p != -1)
    {
        g << v[p] << " ";
        p=poz[p];
    }
    return 0;
}