Pagini recente » Cod sursa (job #231372) | Cod sursa (job #282068) | Cod sursa (job #3131330) | Cod sursa (job #821749) | Cod sursa (job #2104480)
#include <iostream>
#include <fstream>
#define nmax 100000
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,a[nmax+5],best[nmax+5],poz[nmax+5];
int main()
{
int vmax=1,x=n;
fin>>n;
for(int i=1;i<=n;i++)
fin>>a[i];
best[n]=1;
poz[n]=-1;
for(int i=n-1;i>=1;--i)
{
best[i]=1;
poz[i]=-1;
for(int j=i+1;j<=n;++j)
if(a[i]<a[j] && best[i]<best[j]+1)
{
best[i]=best[j]+1;
poz[i]=j;
if(best[i]>vmax) vmax=best[i];x=i;
}
}
fout<<vmax<<"\n";
int i=x;
while(i!=-1)
{
fout<<a[i]<<" ";
i=poz[i];
}
return 0;
}