Pagini recente » Cod sursa (job #1460552) | Cod sursa (job #32698) | Cod sursa (job #924161) | Cod sursa (job #2493270) | Cod sursa (job #1437699)
#include <iostream>
#include<fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, k,vmax ,a, v[100001], x[100001], pos[100001];
int main()
{
fin>>n;
for(int i=1;i<=n;i++) fin>>v[i];
x[n]=1;
k=n;
pos[n]=n+1;
for(int i=n-1;i;i--)
{ int xmax=0;
a=i;
for(int j=i+1;j<=n;j++)
if(v[j]>v[i] && xmax<x[j]) {xmax=x[j];a=j;}
x[i]=1+xmax;
pos[i]=a;
if(x[k]<x[i]) k=i;
}
fout<<x[k]<<'\n';
int j=k;
while(pos[j]!=0)
{ fout<<v[j]<<" ";
j=pos[j];
}
fout.close();
return 0;
}