Submission details
Task:Järjestys
Sender:Guuber3
Submission time:2025-09-07 10:35:21 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool simulate(std::vector<std::pair<int, int> >)':
input/code.cpp:6:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |         for (int i = 0; i < points.size() - 1; i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~
input/code.cpp: In function 'void solve()':
input/code.cpp:28:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   28 |                 sort(points.begin(), points.end());
      |                 ^~~~
      |                 short
input/code.cpp:34:26: error: 'next_permutation' was not declared in this scope
   34 |                 } while (next_permutation(points.begin(), points.end()));
      |                          ^~~~~~~~~~~~~~~~
input/code.cpp:39:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   39 |         sort(points.begin(), points.end());
      |...

Code

#include<iostream>
#include<vector>
using namespace std;

bool simulate(vector<pair<int, int> > points) {
	for (int i = 0; i < points.size() - 1; i++) {
		if (points[i].second > points[i+1].first) return false;
	}
	return true;
}

void success(vector<pair<int, int> > points) {
	cout << "YES\n";
	for (auto u : points) cout << u.first << " " << u.second << "\n";
}

void fail() {
	cout << "NO\n";
}

void solve() {
	int n;
	cin >> n;
	vector<pair<int,int> > points(n);
	for (auto &[a, b] : points) cin >> a >> b;
	
	if (n <= 5) {
		sort(points.begin(), points.end());
		do {
			if (simulate(points)) {
				success(points);
				return;
			}
		} while (next_permutation(points.begin(), points.end()));
		fail();
		return;
	}

	sort(points.begin(), points.end());
	if (simulate(points)) success(points);
	else fail();
}

int main() {
	int t;
	cin >> t;
	while (t--) solve();
}