Cod sursa(job #580490)

Utilizator gyeresihunorGyeresi Hunor gyeresihunor Data 13 aprilie 2011 09:19:44
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include "stdio.h"


int i, n, j;
int max=0;
int hol=0;
int t[100100];
int s[100100];

int main()
{
	freopen("scmax.in","r",stdin);
	freopen("scmax.out","w",stdout);
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&t[i]);
	for(i=n;i>0;i--)
	{
		for(j=i+1;j<=n;j++)
			if(t[i]<t[j]&&s[i]<s[j])
				s[i]=s[j];
		s[i]++;
		if(s[i]>max)
		{
			max=s[i];
			hol=i;
		}
	}
	printf("%d\n",max);
	for(i=hol;i<=n;i++)
		if(s[i]==max)
		{
			printf("%d ",t[i]);
			max--;
		}
}