Cod sursa(job #1760208)

Utilizator AndreidgDragomir Andrei Valentin Andreidg Data 20 septembrie 2016 15:23:24
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int i,j,n,k;
unsigned int v[100002];
unsigned int l[100002];
unsigned int poz[100002];
unsigned int stiva[100002];
unsigned x1,x,Max;
bool ok;
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>v[i];
        x=v[i];ok=0;
        poz[i]=i;
        l[i]=1;
        for(j=i-1;j>=1;j--)
        {
            if(x>v[j])
            {
                if(!ok)
                {
                    poz[i]=j;
                    ok=1;
                }
                l[i]++;
                x=v[j];
            }
        }
        if(l[i]>Max)
        {
            Max=l[i];
            x1=i;
        }
    }
    g<<Max<<"\n";
    k=1;
    while(x1!=poz[x1])
    {
        //g<<v[x]<<" ";
        stiva[k]=x1;
        x1=poz[x1];
        k++;
    }
    stiva[k]=x1;
    for(i=k;i>=1;i--)
    {
        g<<v[stiva[i]]<<" ";
    }
    //g<<v[x];
    f.close();
    g.close();
    return 0;
}