Submission
Status:
[PPP-SSSSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: colo39
Problemset: วันว่างๆ
Language: cpp
Time: 0.002 second
Submitted On: 2026-11-22 14:14:38
#include <bits/stdc++.h>
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
vector<pair<int,int>> vec;
while (q--) {
int n;
cin >> n;
while (n--) {
int x,y;
cin >> x >> y;
vec.push_back({x,1});
vec.push_back({y,-1});
}
}
sort(vec.begin(),vec.end(),[](const auto &a, const auto &b){
if (a.first != b.first) return a.first < b.first;
return a.second < b.second;
});
int cur = 0;
bool ch = 0;
pair<int,int> hold;
vector<pair<int,int>> ans;
for (auto &x : vec) {
cur += x.second;
if (cur == 0 && ch == 0) {
hold.first = x.first;
ch = 1;
}
if (ch == 1 && cur != 0) {
hold.second = x.first;
ch = 0;
ans.push_back(hold);
}
}
for (auto &x : ans) {
cout << x.first << " " << x.second << " ";
}
if (ans.size() == 0) cout << -1;
return 0;
}