Pagini recente » Istoria paginii runda/aasfa | Cod sursa (job #415379) | Istoria paginii runda/pregatire_oji_4/clasament | Cod sursa (job #766123) | Cod sursa (job #738820)
Cod sursa(job #738820)
#include<stdio.h>
#define dim 100005
int n,v[dim],best[dim],urmator[dim];
int main(){
int i,j,beg,max=0;
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&v[i]);
best[i]=1;
}
for(i=n-1;i>=1;i--){
for(j=i+1;j<=n;j++){
if(v[i]<v[j] && best[j]+1>best[i]){
best[i]=best[j]+1;
urmator[i]=j;
if(max<best[i]){
max=best[i];
beg=i;
}
}
}
}
printf("%d\n",max);
for(i=beg;i;i=urmator[i]) printf("%d ",v[i]);
return 0;
}