Cod sursa(job #731085)

Utilizator LauraBBuf Laura LauraB Data 7 aprilie 2012 14:30:05
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>
using namespace std;

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

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