CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Kortit
Sender:FooBat
Submission time:2020-09-27 07:48:57 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:28:8: error: 'sort' is not a member of 'std'
   std::sort(input.begin(), input.end());
        ^~~~
input/code.cpp:28:8: note: suggested alternative: 'cout'
   std::sort(input.begin(), input.end());
        ^~~~
        cout

Code

#include <iostream>
#include <array>
#include <vector>
int main()
{

	int tests, n;
	std::cin >> tests;
	std::array<int, 101> own;
	std::array<int, 101> opponent;

	std::vector<int> input;
	std::vector<int> results;
	for (int t = 0; t < tests; t++)
	{
		std::cin >> n;
		int x = n / 2;
		int nextCard = 1;
		int oppIdx = 0;
		int ownIdx = 0;
		input.clear();
		for (int i = 0; i < x; i++)
		{
			int card;
			std::cin >> card;
			input.emplace_back(card);
		}
		std::sort(input.begin(), input.end());
		for (int card : input)
		{

			while (card > nextCard)
			{
				opponent[oppIdx++] = nextCard++;
			}
			own[ownIdx++] = nextCard++;
		}
		while (oppIdx < x)
		{
			opponent[oppIdx++] = nextCard++;
		}

		/*
		for (int p = 0; p < x; p++)
			std::cout << "Own: " << own[p] << std::endl;
		for (int p = 0; p < x; p++)
			std::cout << "Opp: " << opponent[p] << std::endl;
		*/

		int playedBig = 0;
		int playedSmall = 0;
		int won = 0;
		for (int i = 0; i < x; i++) 
		{
			int oc = opponent[x - 1 - i];
			int big = own[x - 1 - playedBig];
			if (big > oc) 
			{
				won++;
				playedBig++;
			}
			else 
			{
				if (own[playedSmall++] > oc) 
				{
					won++;
				}
			}
		}
		results.emplace_back(won);
	}
	for (int w : results) 
	{
		std::cout << w << "\n";
	}
	return 0;
}