Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: syndrxme
Problemset: วันว่างๆ
Language: cpp
Time: 0.020 second
Submitted On: 2026-03-14 09:24:50
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
vector<pair<int,int>> event;
for(int i=0;i<n;i++){
int m;
cin>>m;
for(int j=0;j<m;j++){
int s,e;
cin>>s>>e;
event.push_back({s,-1});
event.push_back({e,1});
}
}
sort(event.begin(), event.end());
// for(auto& c:event){
// cout<<c.first<<" "<<c.second<<endl;
// }
int nowbusy=0;
int last=-1;
vector<pair<int,int>> ans;
for(auto& e:event){
int curtime = e.first;
int type = e.second;
if(nowbusy==0 && type==-1 && last!=-1){
if(curtime>last){
ans.push_back({last,curtime});
}
}
if(type==-1){
nowbusy++;
}else{
nowbusy--;
}
if(nowbusy==0){
last = curtime;
}
}
if(ans.empty()==true){
cout<<-1;
}else{
for(auto& p:ans){
cout<<p.first<<" "<<p.second<<" ";
}
}
return 0;
}