Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: KantaponZ
Problemset: วันว่างๆ
Language: cpp
Time: 0.016 second
Submitted On: 2025-07-28 00:56:22
#include <bits/stdc++.h>
using namespace std;
int N, R = 0, L = 1e9;
int x[1005];
bool st = 0;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N;
while (N--) {
int M;
cin >> M;
while (M--) {
int S, E;
cin >> S >> E;
R = max(R, E);
L = min(L, S);
x[S]++;
x[E]--;
}
}
int sum = 0;
int t;
vector<pair<int,int>> v;
for (int i = L; i <= R; i++) {
sum += x[i];
if (sum == 0 && st == 0) {
t = i;
st = 1;
}
if (sum != 0 && st == 1) {
v.emplace_back(t, i);
st = 0;
}
}
sort(v.begin(), v.end());
bool pr = false;
for (auto [a, b] : v) {
if (a == b) continue;
cout << a << " " << b << " ";
pr = true;
}
if (!pr) cout << -1;
}