Pagini recente » Cod sursa (job #31656) | Cod sursa (job #1646192) | Infoarena Monthly 2014 - Solutii Runda 3 | Cod sursa (job #2451172) | Cod sursa (job #719931)
Cod sursa(job #719931)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int main()
{
int a[100005],l[100005],next[100005],n;
fin>>n;
for(int i=1;i<=n;i++)
fin>>a[i];
l[n]=1;
next[n]=-1;
for(int i=n-1;i>=1;i--)
{
l[i]=1;
next[i]=-1;
for(int j=i+1;j<=n;j++)
if(a[i]<a[j] && l[i]<1+l[j])
{
l[i]=1+l[j];
next[i]=j;
}
}
int pmax=0;
l[0]=-1;
for(int i=1;i<=n;i++)
if(l[i]>l[pmax])
pmax = i;
fout<<l[pmax]<<'\n';
for( ; pmax!=-1;pmax=next[pmax])
fout<<a[pmax]<<' ';
return 0;
}