Pagini recente » Cod sursa (job #2870450) | Cod sursa (job #2691347) | Cod sursa (job #537161) | Cod sursa (job #3185679) | Cod sursa (job #1529808)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int v[100005], lung[100005], n, i, j, lmax, smax, pmax, x[100005] , p;
int main()
{ fin >> n;
for(i = 1 ; i <= n ; i++)
fin>>v[i];
for(i = 1 ; i <= n ; i++)
{ lmax=0;
for(j=1;j<=i-1;j++)
{
if(v[i]>v[j] && lung[j]>lmax)
{
lmax=lung[j];
x[i] = j;
}
}
lung[i]=lmax+1;
if(lung[i]>smax)
{ smax=lung[i];
pmax=i;
}
}
fout << smax <<'\n';
for(i = pmax; i >= 1 ; i = x[i])
{ p++;
x[p]=v[i];
}
for(i=p ; i >= 1 ; i--)
{
if(x[i] != 0)
fout << x[i]<<' ';
}
return 0;
}