Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Nathako9n
Problemset: วันว่างๆ
Language: cpp
Time: 0.010 second
Submitted On: 2026-02-08 10:40:19
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define f first
#define s second
#define ll long long
using namespace std;
const int N = 10005,M=1e5+5;
int n;
ll ar[M+2];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
int mx=0;
for(int i=1;i<=n;i++){
int t;cin>>t;
while(t--){
int x,y;cin>>x>>y;
++ar[x]; --ar[y];
mx=max(mx,y);
}
}
for(int i=1;i<=1e5+3;i++){
ar[i]+=ar[i-1];
}
int in=-1;
bool ch=1;
bool vl=1;
for(int i=1;i<=mx;i++){
if(ar[i]==0&&ch)continue;
if(ar[i]!=0)ch=0;
if(ar[i]==0&&in==-1){
in=i;
}
if(ar[i]>0){
if(in!=-1){
cout<<in<<" "<<i<<" ";
vl=0;
in=-1;
}
}
//cout<<i<<" "<<ar[i]<<endl;
}
if(vl){
cout<<-1;
}
//cout<<vl;
return 0;
}
/*
3
2 1 3 6 7
1 2 4
2 2 5 9 12
3
2 1 2 5 6
1 1 3
1 4 10
2
1 3 5
1 3 4
*/