Cod sursa(job #1089815)

Utilizator cricriFMI - Radu Vlad cricri Data 21 ianuarie 2014 22:40:53
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
using namespace std;

#include<fstream>
#include<iostream>

ifstream f("scmax.in");
ofstream g("scmax.out");

struct specialNr
{
	int value, prev, count;
};

int n;

specialNr best[100001];


void write(int p)
{
	if(best[p].prev != 0)
		write(best[p].prev);
	g<<best[p].value<<' ';
}


int main()
{
	int i,j;
	f>>n;
	for(i=1;i<=n;i++)
	{
		f>>best[i].value;
		for(j=1;j<i;j++)
			if(best[j].value < best[i].value && best[j].count >= best[i].count)
			{
				best[i].count = best[j].count+1;
				best[i].prev = j;
			}
	}

	int poz,max = -1;
	//select max
	for(i=1;i<=n;i++)
	{
		if(max<best[i].count)
		{
			max = best[i].count;
			poz = i;
		}
	}

	g<<max+1<<'\n';

	write(poz);


	return 0;
}