Cod sursa(job #1320086)

Utilizator turnenTudor Oprescu turnen Data 17 ianuarie 2015 16:25:54
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <fstream>

using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int lungime,numere[100001],sir[100001],drum[100001],rez1=0,poz,rez2[100001],rezpoz=1;
int main()
{
    int i,j,Max=0;;
    in>>lungime;
    for(i=1; i<=lungime; i++)
    {
        in>>numere[i];
    }
    for(i=1; i<=lungime; i++)
    {
        Max=0;
        for(j=i-1; j>=1; j--)
        {
            if(numere[j]<numere[i]&&sir[j]>Max)
            {
                Max=sir[j];
                drum[i]=j;
            }
        }
        sir[i]=Max+1;
    }
    for(i=1; i<=lungime; i++)
    {
        if(i[sir]>rez1)
        {
            rez1=sir[i];
            poz=i;
        }

    }
    out<<rez1<<endl;
    while(poz){

    rez2[rezpoz]=numere[poz];
    poz=drum[poz];
    rezpoz++;
    }
    for(i=rezpoz-1;i>=1;i--){
    out<<rez2[i]<<" ";
    }

}