Cod sursa(job #1755727)

Utilizator victorungu99Victor Gabriel Ungureanu victorungu99 Data 10 septembrie 2016 21:15:16
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <fstream>
#include <iterator>
#include <vector>

int main()
{
	std::ifstream FIn("scmax.in");
	std::ofstream FOut("scmax.out");
	std::vector<std::vector<int> > Lists;
	std::vector<int> A;
	int N,
		A_i, list_i,
		TempSize, MaxListIndex = 0,
		Min = 3000000000,
		Max = 0;

	FIn >> N;
	A.reserve(N);
	std::copy((std::istream_iterator<int>(FIn)), std::istream_iterator<int>(), std::back_inserter(A));

	for (int i = 0; i < N; i++)
	{
		A_i = A[i];

		if (A_i < Min)
		{
			Min = A_i;

			Lists.push_back(std::vector<int>());
			Lists.back().push_back(A_i);

			continue;
		}

		for (auto& list : Lists)
		{
			list_i = list.back();

			if (A_i > list_i)
				list.push_back(A_i);

			if (A_i < list_i)
				list.back() = A_i;
		}
	}

	for (const auto& i : Lists)
	{
		TempSize = static_cast<int>(i.size());
		if (TempSize > Max)
		{
			Max = TempSize;
			MaxListIndex++;
		}
	}

	MaxListIndex--;

	FOut << Max << " ";
	std::copy(Lists[MaxListIndex].begin(), Lists[MaxListIndex].end(), std::ostream_iterator<int>(FOut, " "));

	return 0;
}