Cod sursa(job #2044910)

Utilizator grecubogdanGrecu Bogdan grecubogdan Data 21 octombrie 2017 16:31:53
Problema Subsir crescator maximal Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int a[100001],l[100001],t[100001],n,i,v,j,pmax,vfc;
int main()
{
 f>>n;
 for(i=1;i<=n;i++)
    f>>a[i];
 for(i=n;i>=1;i--)
 {
     v=0;
        t[i]=0;
     for(j=i+1;j<=n;j++)
     {
         if(a[i]<a[j]&&l[j]>v)
         {
             v=l[j];
             t[i]=j;
         }
         l[i]=v+1;
     }
 }
 pmax=1;
    for (int i=2;i<=n;i++)
        if (l[i]>l[pmax])
            pmax=i;
    g<<l[pmax]<<'\n';
 vfc=pmax;
    while (vfc!=0)
    {
        g<<a[vfc]<<" ";
        vfc=t[vfc];
    }

 return 0;
}