Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Kx
Problemset: วันว่างๆ
Language: cpp
Time: 0.365 second
Submitted On: 2026-03-18 12:42:08
#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<int, int>> vpii;
vpii p;
void getp(int l, int r) {
vpii cur;
for(auto &[x, y] : p) {
if(r < x || l > y) {
cur.push_back({x, y});
} else {
l = min(l, x);
r = max(r, y);
}
}
cur.push_back({l, r});
p = cur;
}
int main() {
int n; cin >> n;
while(n--) {
int m; cin >> m;
while(m--) {
int l, r; cin >> l >> r;
getp(l, r);
}
}
sort(p.begin(), p.end());
vpii res;
for(int i = 0; i < (int)p.size() - 1; ++i) {
if(p[i + 1].first - p[i].second > 0) {
res.push_back({p[i].second, p[i + 1].first});
}
}
if(res.size() == 0) {
cout << -1;
return 0;
}
for(auto [x, y] : res) {
cout << x << ' ' << y << ' ';
}
return 0;
}