Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Nay-O
Problemset: วันว่างๆ
Language: cpp
Time: 0.031 second
Submitted On: 2026-03-26 14:06:34
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
priority_queue<pii,vector<pii>,greater<pii>> pq;
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin>>n;
for(int i = 0; i < n; i++){
int m; cin>>m;
while(m--){
int a,b; cin>>a>>b;
pq.push({a,-1}); pq.push({b,1});
}
}
int c = 0;
vector<int> ans;
while(!pq.empty()){
if(ans.size()%2==1){
ans.push_back(pq.top().first);
}
c-=pq.top().second;
if(c==0){
ans.push_back(pq.top().first);
}
pq.pop();
}
ans.pop_back();
for(auto value : ans){
cout << value << " ";
}
if(ans.size()==0){
cout << -1;
}
return 0;
}