Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
- int main() {
- FASTIO;
- int t;
- cin >> t;
- for (int i = 1; i <= t; i++) {
- int n;
- cin >> n;
- vector<pair<int, int>> h;
- for (int j = 0; j < n; j++) {
- int x, y;
- cin >> x >> y;
- h.push_back(make_pair(x, y));
- }
- vector<pair<int, int>> aux = h;
- sort(h.begin(), h.end());
- string ans = "C";
- int c = h[0].second, j = -1;
- for (int k = 1; k < n; k++) {
- if (h[k].first >= j) {
- ans += "J";
- j = h[k].second;
- }
- else if (h[k].first >= c) {
- ans += "C";
- c = h[k].second;
- }
- else {
- ans = "IMPOSSIBLE";
- break;
- }
- }
- if (ans != "IMPOSSIBLE") {
- string now = "";
- for (int k = 0; k < n; k++) {
- for (int z = 0; z < n; z++) {
- if (h[z] == aux[k]) {
- now += ans[z];
- break;
- }
- }
- }
- cout << "Case #" << i << ": " << now << endl;
- }
- else {
- cout << "Case #" << i << ": " << ans << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement