Pagini recente » Cod sursa (job #3257062) | Cod sursa (job #2581586) | Cod sursa (job #149171) | Cod sursa (job #1150608) | Cod sursa (job #329999)
Cod sursa(job #329999)
#include<stdio.h>
using namespace std;
long long v[100001];
int n,best[100001],poz[100001];
int main()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
int i,j,max,p;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%lld",&v[i]);
best[n]=1;
poz[n]=-1;
max=1;
for(i=n-1;i>=1;i--)
{
best[i]=1;
poz[i]=-1;
for(j=i+1;j<=n;j++)
{
if(v[i]<v[j] && best[i]<best[j]+1)
{
best[i]=best[j]+1;
poz[i]=j;
if(best[i]>max) {max=best[i];p=i;}
}
}
}
printf("%d\n",max);
i=p;
while(i!=-1)
{
printf("%lld ",v[i]);
i=poz[i];
}
return 0;
}