Pagini recente » Istoria paginii runda/bulangandit11/clasament | Cod sursa (job #671196) | Istoria paginii runda/simulareoji2015p2/clasament | Cod sursa (job #2810414) | Cod sursa (job #678879)
Cod sursa(job #678879)
#include<cstdio>
#define lim 100002
using namespace std;
int e[lim],h,i,t,S[lim],max,n;
int main (){
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n),S[n]=1;
for(i=1;i<=n;i++)
scanf("%d",&e[i]);
for(h=n-1;h>=1;h--){
max=0;
for(i=h+1;i<=n;i++)
if(e[h]<e[i] &&S[i]>max)
max=S[i];
S[h]=max+1;
}
max=S[1],t=1;
for(i=1;i<=n;i++)
if(max<S[i]){
max=S[i];t=i;
}
printf("%d\n%d ",max,e[t]);
for(i=t+1;i<=n;i++){
if(e[i]>e[t] && S[i]==max-1){
printf("%d ",e[i]);
--max;
}
}
return 0;
}