Cod sursa(job #1529875)

Utilizator cristy801Cristi Chirtos cristy801 Data 21 noiembrie 2015 11:30:54
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <fstream>
#include <cmath>

using namespace std;

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

int v[100005],l[100005],lmax,ant[100005],maxx=0,antr,afis[100005],m;
int afisare (int top)
{
    if (v[top]==0) return 0;
    afisare(ant[top]);
    g<<v[top]<<" ";
}

int main()
{
    int n;
    f>>n;
    for (int i=1;i<=n;i++)
        f>>v[i];

    for (int i=1;i<=n;i++)
    {
        lmax=0;
        ant[i]=0;
        for (int j=1;j<=i-1;j++)
        {
            if (v[i]>v[j])
                if (l[j]>lmax)
                {
                    lmax=l[j];
                    ant[i]=j;
                }
        }
        l[i]=lmax+1;
        if (maxx<l[i])
        {
            maxx=l[i];
            antr=i;
        }
    }
    g<<maxx<<"\n";
    afisare(antr);
    return 0;
}