Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Score: 100
User: FotoFatTurtle
Problemset: วันว่างๆ
Language: cpp
Time: 0.033 second
Submitted On: 2025-04-01 22:34:27
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int num,temp,st,en,maxi=-2e9,mini=2e9;
cin>>num;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
for(int i=0;i<num;i++)
{
cin>>temp;
for(int j=0;j<temp;j++)
{
cin>>st>>en;
q.push({st,1});
q.push({en,-1});
maxi=max(maxi,en);
mini=min(mini,st);
//cout<<st<<" "<<en<<" "<<2*temp<<"\n";
}
}
int nub=0;
bool go=false;
bool out=false;
for(int i=mini;i<=maxi;i++)
{
if(nub!=0&&go==true)
{
go=false;
cout<<st<<" "<<i-1<<" ";
out=true;
}
while(!q.empty()&&q.top().f==i)
{
nub+=q.top().s;
q.pop();
}
//cout<<i<<" "<<nub<<"\n";
if(nub==0&&go==false)
{
go=true;
st=i;
}
}
if(out==false)
cout<<"-1";
/*while(!q.empty())
{
cout<<q.top().f<<" "<<q.top().s<<"\n";
q.pop();
}*/
}