Cod sursa(job #1934968)
| Utilizator | Data | 21 martie 2017 22:09:48 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.75 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int lg[100004],n,lmax,pmax=-1,i,j,poz[100004];
long long v[100004];
int main()
{
f>>n;
for(i=1; i<=n; i++)
f>>v[i];
poz[n]=-1;
lg[n]=1;
for(i=n-1;i;i--)
{
lg[i]=1;
poz[i]=-1;
for(j=i+1; j<=n; j++)
{
if(v[i]<v[j] && lg[i]<lg[j]+1)
{
lg[i]=lg[j]+1;
poz[i]=j;
}
}
if(lg[i]>lmax)
{
lmax=lg[i];
pmax=i;
}
}
g<<lmax<<'\n';
while(pmax!=-1)
{
g<<v[pmax]<<" ";
pmax=poz[pmax];
}
return 0;
}
