Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: tha_smith
Problemset: วันว่างๆ
Language: cpp
Time: 0.010 second
Submitted On: 2026-02-27 15:55:31
#include <bits/stdc++.h>
using namespace std;
int d[1002],s,e,st,N,M,cnt;
vector<pair<int,int>> ans;
int main() {
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> N;
for(int i=1; i<=N; i++) {
cin >> M;
while(M--) {
cin >> s >> e;
d[s]++;
d[e]--;
}
}
for(int i=0; i<=1001; i++) {
cnt +=d[i];
if(st==0 && cnt==0) {
s=i;
st=1;
}
else if(st==1 && cnt!=0) {
e=i;
st=0;
ans.push_back({s,e});
}
}
int sz=0;
for(int i=0; i<ans.size(); i++) {
if(ans[i].first==0 || ans[i].second==1001)
continue;
cout << ans[i].first << ' ' << ans[i].second << ' ';
sz++;
}
if(sz==0)
cout << -1;
}