Pagini recente » Cod sursa (job #1081041) | Cod sursa (job #1776346) | Cod sursa (job #3147154) | Rating Sebestyen Ioana-Maria (dark_me) | Cod sursa (job #693843)
Cod sursa(job #693843)
#include<stdio.h>
using namespace std;
int main ()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
int n,a[100002]={0},best[100002],i,j,max=0,m,v[100002]={0};
scanf("%d%d",&n,&a[0]);
best[0]=1;
for(i=1;i<n;i++){
scanf("%d",&a[i]);
m=i;
for(j=0;j<i;j++){
if(a[i]>a[j]&best[m]<best[j])
m=j;}
best[i]=best[m]+1;
if(v[best[i]]!=0){
if(v[best[i]]>a[i])
v[best[i]]=a[i];}
else
v[best[i]]=a[i];
if(best[i]>max){
max=best[i];}}
printf("%d\n",max);
for(i=1;i<=max;i++)
printf("%d ",v[i]);
return 0;
}