Pagini recente » Cod sursa (job #1516161) | Monitorul de evaluare | Cod sursa (job #648752) | Cod sursa (job #2905805) | Cod sursa (job #3301410)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,v[100011],best[100011],ant[100011],maxim,poz;
int rez[100011],lng;
int main()
{
fin>>n;
for(int i=1; i<=n; i++)
fin>>v[i];
for(int i=1; i<=n; i++)
{
best[i]=1;
ant[i]=-1;
for(int j=1; j<i; j++)
{
if(v[j]<v[i] && best[j]+1>best[i])
{
best[i]=best[j]+1;
ant[i]=j;
}
}
if(best[i]>maxim)
{
maxim=best[i];
poz=i;
}
}
fout<<maxim<<'\n';
while(poz!=-1)
{
rez[++lng]=v[poz];
poz=ant[poz];
}
for(int i=lng; i>=1; i--)
fout<<rez[i]<<' ';
return 0;
}