Cod sursa(job #356861)

Utilizator darkdudeAndrei Barsan darkdude Data 17 octombrie 2009 10:19:28
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream.h>

using namespace std;

int main()
{
    long a[100003], l[100003], n, m;
    long i, j, max;
    ifstream f("scmax.in");
    f>>n;
    for(i=1; i<=n; ++i)
        f>>a[i];
    f.close();

    l[n]=1;
    for(i=n-1; i>=1; i--)
        {
            max = 0;
            for(j=i+1; j<=n; j++)
                if(a[j]>a[i])
                    if(max < l[j])
                    max = l[j];

            l[i]=1+max;
        }

    int imax;
    max = 0;
    for(i=1; i<=n; i++)
        if(l[i]>max) { max = l[i]; imax = i; }

    freopen("scmax.out","w",stdout);

    cout<<max<<"\n"<<a[imax];
    max--;

    while(max>0)
        {
            while(l[imax]!=max)
                {
                    imax++;
                }
            cout<<" "<<a[imax];
            max--;
        }




    return 0;
}