Pagini recente » Cod sursa (job #2792397) | Cod sursa (job #3139854) | Cod sursa (job #1429489) | Cod sursa (job #178989) | Cod sursa (job #599019)
Cod sursa(job #599019)
#include <stdio.h>
using namespace std;
long j,i,N,crt,nr[100001],max[100001],gmax,sf;
int main ()
{
freopen("scmax.in", "r", stdin);
freopen("scmax.out", "w", stdout);
scanf("%d", &N);
for (i=1; i<=N; i++)
{
scanf("%d", &nr[i]);
}
for (i=N; i>=1; i--)
{
max[i]=1;
gmax=0;
for (j=N; j>=i+1; j--)
if (nr[i]<nr[j] && max[j]>max[gmax]) gmax=j;
if (gmax) max[i]=max[gmax]+1;
if (max[i]>max[sf]) sf=i;
}
printf("%d\n%d ", max[sf], nr[sf]);
crt=nr[sf];
for (i=sf; i<=N; i++)
if (nr[i]>crt)
{
printf("%d ", nr[i]);
crt=nr[i];
}
return 0;
}