Pagini recente » Cod sursa (job #2099269) | Cod sursa (job #2169779) | Cod sursa (job #2633182) | Cod sursa (job #2031271) | Cod sursa (job #1640391)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
long long x[100001],z[100001],start[100001];
int n,i,smax,j,ok;
int main()
{
f >> n;
for (i=1;i<=n;i++)
f >> x[i];
z[n]=1;start[n]=0;
for (i=n-1;i>=1;i--)
{
for (j=1;j<=n;j++)
if (x[i]<x[j] && z[i]<=z[j]) {z[i]=z[j]+1;start[i]=j;ok=1;}
if (!z[i]) {z[i]=1; start[i]=0;}
if (z[i]>z[smax]) smax=i;
}
g << z[smax] << "\n";
while (start[smax])
{
g << x[smax] << ' ';
smax=start[smax];
}
g << x[smax];
return 0;
}