Cod sursa(job #1160661)

Utilizator DysKodeTurturica Razvan DysKode Data 30 martie 2014 18:13:20
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <fstream>
using namespace std;

ifstream fin("scmax.in");
ofstream fout("scmax.out");

int v[100010],poz[100010],lung[100010],a,b,x,k,tot,n,toti;


void citire ()
{ int i;
    fin>>n;
    for(i=1 ; i<=n ; i++)
    {
        fin>>v[i];
        lung[i]=1;
    }
}

void rezolvare ()
{int i,j,maxi;
    for(i=n-1 ; i>=1 ; i--)
    {
        maxi=1;
        for(j=i+1 ; j<=n ; j++)
        {
            if(v[i]<v[j])
                a=lung[j]+1;
            if(a>=maxi)
            {
                maxi=a;
                lung[i]=a;
                poz[i]=j;
            }
        }
    }
}

void total ()
{int i;
    for(i=1 ; i<=n ; i++)
        if(lung[i]>toti)
        {
            toti=lung[i];
            tot=i;
        }
}

void afisare()
{int i,k;
    i=tot;
    k=toti;
    while(poz[i]!=0)
    {
        fout<<v[i]<<" ";
        i=poz[i];
    }
}

int main()
{
    citire();
    rezolvare();
    total();
    fout<<toti<<"\n";
    afisare();

fin.close();
fout.close();
return 0;
}