Cod sursa(job #509181)

Utilizator George25Raduta George Cristian George25 Data 10 decembrie 2010 17:16:44
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#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);
}