Cod sursa(job #2058975)

Utilizator antonia.gheorgheGheorghe Antonia antonia.gheorghe Data 6 noiembrie 2017 15:18:29
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>

using namespace std;

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

int a[100000], n, lmax, pmax, l[100000], u,i,j,ma,k,v[100000];

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

    l[1]=1;
    pmax=1;
    lmax=1;

    for (i=2;i<=n;i++)
    {
        ma=0;

        for (j=1;j<=i-1;j++)
        if (a[i]>a[j] && l[j]>ma) ma=l[j];

        l[i]=1+ma;

        if ( l[i]> lmax)
        {
            lmax=l[i];
            pmax=i;
        }

    }

g<< lmax<<endl; k=lmax;
     v[lmax]=a[pmax];

    lmax--;
    u=a[pmax];

    for (i=pmax+1;i>=1;i--)

        if (l[i]==lmax && a[i]<u)
        {
            v[lmax]=a[i];
            u=a[i];
            lmax--;
        }
    for (i=1;i<=k;i++)
        g<<v[i]<<" ";
    return 0;

}