Cod sursa(job #429786)

Utilizator soare_cristian16Cristy93 soare_cristian16 Data 30 martie 2010 14:19:50
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include<fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[100001],n,poz[100001],z;
int caut(int x, int y)
{
	int i,pas=1<<16;
	for(i=0;pas;pas>>=1)
		if(i+pas<=y&&v[i+pas]<x)
			i+=pas;
	if(poz[i+2]<z&&poz[i+2])
		return -2;
	if(v[i+1]<x)
		return -1;
	return i+1;
}
int main()
{
	int i=1,x,y;
	f>>n>>v[1];
	while(f>>x)
	{
		z++;
		y=caut(x,i);
		if(y==-1)
		{
			v[++i]=x;
			poz[i]=z;
		}
		else
		if(y>=0)
		{
			poz[y]=z;
			v[y]=x;
		}
	}
	g<<i<<"\n";
	for(y=1;y<=i;y++)
		g<<v[y]<<" ";
	return 0;
}