Submission details
Task:Järjestys
Sender:pupukani
Submission time:2025-09-05 22:53:21 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:77:29: error: no matching function for call to 'shuffle(std::vector<Pari>::iterator, std::vector<Pari>::iterator)'
   77 |                 std::shuffle(parit.begin(), parit.end());
      |                 ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from input/code.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3729:5: note: candidate: 'template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)'
 3729 |     shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~~
/usr/include/c++/11/bits/stl_algo.h:3729:5: note:   template argument deduction/substitution failed:
input/code.cpp:77:29: note:   candidate expects 3 arguments, 2 provided
   77 |                 std::shuffle(parit.begin(), parit.end());
      |                 ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cassert>
#include <sstream>

class Pari
{	private: int a, b;
	public:
		Pari(int a, int b) : a(a), b(b)
		{
		}
		Pari(const std::string& str)
		{	std::istringstream asd(str);
			asd>>a>>b;
		}
		bool operator<(const Pari& other) const { return b <= other.a; }
		friend std::ostream& operator<<(std::ostream& os, const Pari& pari)
		{	os << pari.a << " " << pari.b;
			return os;
		}
};

std::stringstream ss;

bool muodostaa_jonon(std::vector<Pari> sorted, std::vector<Pari> unsorted, size_t u, size_t s)
{
	sorted.insert(sorted.begin() + s, unsorted[u]);
	unsorted.erase(unsorted.begin() + u);

	if (unsorted.empty())
	{
		ss << "YES" << std::endl;
		for (const Pari& p : sorted)
			ss << p << std::endl;
		return true;
	}

	for (size_t u = 0; u < unsorted.size(); ++u)
	{
		for (size_t s = 0; s < sorted.size(); ++s)
		{
			if (unsorted[u] < sorted[s] && (s == 0 || sorted[s - 1] < unsorted[u]))
			{
				if (muodostaa_jonon(sorted, unsorted, u, s))
					return true;
			}
			if (sorted[s] < unsorted[u] && (s == sorted.size() - 1 || unsorted[u] < sorted[s + 1]))
			{
				if (muodostaa_jonon(sorted, unsorted, u, s + 1))
					return true;
			}
		}
	}
	return false;
}

int main(void)
{
	int t;
	std::cin >> t;
	for (int ti = 0; ti < t; ++ti)
	{
		int n;
		std::cin >> n;
		std::string asd;
		std::getline(std::cin, asd);
		std::vector<Pari> parit;
		parit.reserve(n);
		for (int ni = 0; ni < n; ++ni)
		{
			std::string line;
			std::getline(std::cin, line);
			parit.push_back(Pari(line));
		}
		std::shuffle(parit.begin(), parit.end());
		if (!muodostaa_jonon({}, parit, 0, 0))
			ss << "NO" << std::endl;
	}
	std::cout << ss.str();
}