Cod sursa(job #731131)

Utilizator LauraBBuf Laura LauraB Data 7 aprilie 2012 15:37:53
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
using namespace std;

ifstream fin("scmax.in");
ofstream fout("scmax.out");

int main()
{
	int lg = 1, lgmax = 1, l = 0, l2 = 0, dr, drmax, a[100000];
	int n;
	fin >> n;
	for(int i = 1; i <= n; i++)
		fin >> a[i];
	a[n+1] = -32000;
	for(int i = 1; i <= n; i++)
		if(a[i + 1] > a[i])
		{
			lg++;
			dr = i + 1;
		}
		else
			if(a[i] == a[i + 1])
			{
				l2++;
				while(a[i] == a[i + 1])
				{
					i++;
					l++;
				}
				i--;
			}
		else
		{
			if(lg > lgmax)
			{
				lgmax = lg;
				drmax = dr;
			}
			lg = 1;
		}
	fout << lgmax << '\n';
	for(int i = drmax - lgmax - l + 1 ; i <= drmax; i++)
		if(a[i] != a[i + 1])
		fout << a[i] << " ";
	fin.close();
	fout.close();
	return 0;
}