Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: onlyme910
Problemset: วันว่างๆ
Language: cpp
Time: 0.037 second
Submitted On: 2026-03-11 09:39:14
#include <bits/stdc++.h>
using namespace std;
int main() {
set<pair<int, int>> time; // starttime and endtime
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int m;
cin >> m;
for (int j = 0; j < m; j++) {
int a, b;
cin >> a >> b;
auto it = time.upper_bound({a, INT_MAX});
if (it != time.begin()) {
it--;
if (it -> second < a) {
it++;
}
}
while (it != time.end() && it->first <= b) {
a = min(a, it->first);
b = max(b, it->second);
it = time.erase(it);
}
time.insert({a, b});
// for (auto i: time) {
// cout << i.first << ' ' << i.second << ' ';
// }
// cout << endl;
}
}
if (time.size() <= 1) {
cout << -1;
return 0;
}
int cnt = 0;
for (pair<int, int> i: time) {
if (cnt == 0) {
cout << i.second << ' ';
} else if (cnt+1 == time.size()) {
cout << i.first;
} else {
cout << i.first << ' ' << i.second << ' ';
}
cnt++;
}
}