Cod sursa(job #175626)

Utilizator sima_cotizoSima Cotizo sima_cotizo Data 10 aprilie 2008 11:03:25
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX_N 100100

int A[MAX_N], T[MAX_N];
int St[MAX_N][2];
int n, i, v, pmx;


int search(int x, int i) {
	int tot, act;
	for ( act=1; act<v; act<<=1 );
	for ( tot=0; act; act>>=1 ) 
		if ( St[tot+act][0] < x && tot+act<=v )
			tot += act;
	if ( tot == v ) 
		++v, pmx = i;
	St[tot+1][0] = x, St[tot+1][1] = i;
	return St[tot][1];
}

void print( int n ) {
	if ( n<0 ) return;
	print( T[n] );
	printf("%d ", A[n]);
}

int main() {
	freopen("scmax.in", "r", stdin);
	freopen("scmax.out","w",stdout);

	scanf("%d", &n);

	scanf("%d", A);
	St[0][1] = -1;
	St[++v][0] = A[0]; St[v][1] = 0;
	T[0] = -1;

	for ( i=1; i<n; ++i ) {
		scanf("%d", A+i);
		T[i] = search(A[i], i);

	}

	printf("%d\n", v);
	print( pmx );
	return 0;
}