Cod sursa(job #725359)

Utilizator butler1234Cioc Stefan butler1234 Data 26 martie 2012 20:36:30
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[100005],p[100005],q[100005];
int i,j,n,mx,x;
void xddd(int fx, int fp)
{
	while (p[fp]!=fx)
		fp--;
	if (fx>1)
		xddd(fx-1,fp-1);
	g<<v[fp]<<" ";
}
int main()
{
	f>>n;
	for (i=1;i<=n;i++)
	{
		f>>v[i];
		x=v[i];
		j=1;
		while (x>q[j] && j<=mx)
			q[j]=x;
		p[i]=j;
		mx=max(mx,j);
	}
	g<<mx<<"\n";
	xddd(mx,n);
}