Pagini recente » Cod sursa (job #2453104) | Cod sursa (job #2904465) | Cod sursa (job #1758615) | Cod sursa (job #1545294) | Cod sursa (job #509181)
Cod sursa(job #509181)
#include<stdio.h>
int i,j,n,o,t,q[100001],tt,p[100001],a[100001],aa[100001],nr;
bool ok;
inline void caut(int s,int d,int x){
int m;
ok=true;
while (s<=d && ok==true){
ok=true;
m=(s+d)/2;
if (x>=q[m-1] && x<q[m]){
q[m]=x;
ok=false;
}
if (x==q[m] || x==q[m-1]) ok=false;
else if (q[m-1]>x) d=m-1;
else if(q[m]<=x) s=m+1;
}
if (ok==true){
o++;
q[o]=x;
}
}
int main(){
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n);
for (i=1; i<=n; i++) scanf("%d",&a[i]);
p[1]=1;
q[1]=a[1];
o=1;
t=1;
for (i=2; i<=n; i++){
caut(1,o,a[i]);
t++;
p[t]=o;
}
nr=p[n];
t=0;
tt=nr;
for (i=n; i>=1; i--){
if (p[i]==nr){
nr--;
t++;
aa[tt-t+1]=a[i];
}
}
for (i=1; i<=p[n]; i++) printf("%d ",aa[i]);
printf("\n");
return(0);
}