Cod sursa(job #856607)

Utilizator ilenitudorIleni Tudor ilenitudor Data 16 ianuarie 2013 19:40:00
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <fstream>
using namespace std;

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

int n,maxx,pmax;
long int a[100005],l[100005],poz[100005];

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

void fl()
{
    poz[n]= -1;
    l[n]=1;
    for(int i=n-1 ; i>=1 ; i--)
    {
        poz[i]=-1;
        for(int k=i+1; k <=n ; k++)
        if(a[i] < a[k] && l[i] <= l[k] )
        {poz[i] = k;
        l[i]+=1+l[k];
        }
    }

}
void afis()
{
    int i;
    i=pmax;
    while(i!=-1)
    {
        fout<<a[i]<< " ";
        i=poz[i];
    }
}
int main()
{
    Read();
    fl();
    for(int i=1 ; i<=n ; i++)
    {
        if(maxx < l[i])
        {
            maxx = l[i];
            pmax = i;
        }
    }
    fout<<maxx<<"\n";
    afis();


    fin.close();
    fout.close();
    return 0;
}