Cod sursa(job #700552)

Utilizator SCBbestofSocaciu-Cumpanasu Bogdan SCBbestof Data 1 martie 2012 10:52:19
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include<stdio.h>
int V[10001],L[10001],i,N,max,imax;
#define MAXINT 30000
void citire()
{
	scanf("%d",&N);
	for(i=1;i<=N;++i)
		scanf("%d",&V[i]);
}

void l_subsir(int V[10001],int L[10001])
{
	int k;
	L[N]=1;
	for(k=N-1;k>=1;--k)
	{
		L[k]=1;
		i=k;
		do
		{
			--i;
		}while((V[k]>V[i])&&(i!=N));
		if(V[k]<=V[i])
			L[k]=L[i]+1;
	}
	max=-MAXINT;
	for(i=1;i<=N;++i)
		if(max<L[i])
		{
			max=L[i];
			imax=i;
		}
}
void afisare()
{
	printf("%d\n",N-imax-1);
	printf("%d",V[imax]);
	max=V[imax];
	for(i=imax+1;i<=N;++i)
		if(max<=V[i])
		{
			max=V[i];
			printf("%d",max);
		}
}
int main()
{
	freopen("scmax.in","r",stdin);
	freopen("scmax.out","w",stdout);
	citire();
	l_subsir(V,L);
	afisare();
	return 0;
}