Pagini recente » Cod sursa (job #2494269) | Cod sursa (job #1554666) | Cod sursa (job #2194431) | Cod sursa (job #2371789) | Cod sursa (job #1655771)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,a[100001],u[100001],L[100001],bestL,bestind;
int main()
{
fin>>n;
for(int i=1; i<=n; i++)
fin>>a[i];
L[n]=1;
u[n]=0;
for(int i=n-1; i>=1; i--)
{
int max=0,ind=0;
for(int j=i+1; j<=n; j++)
{
if(a[j]>a[i]&&L[j]>max)
{
max=L[j];
ind=j;
}
L[i]=1+max;
u[i]=ind;
if(max+1>bestL)
{
bestL=max+1;
bestind=i;
}
}
}
fout<<bestL<<endl;
int ind=bestind;
do{
fout<<a[ind]<<" ";
ind=u[ind];
}while(ind);
return 0;
}