Submission

Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]

Score: 100

User: mydKN

Problemset: วันว่างๆ

Language: cpp

Time: 0.033 second

Submitted On: 2025-03-30 21:33:27

#include<bits/stdc++.h>

using namespace std;

struct stc{
	int s, t;
	bool operator<(const stc& a) const{
		if(s != a.s) return s > a.s;
		return t < a.t;
	}
};

const int inf = 2e9;

int n;
priority_queue<stc> pq;
int sum;
bool chk;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for(int i=0;i<n;++i){
		int m;
		cin >> m;
		for(int j=0;j<m;++j){
			int s, t;
			cin >> s >> t;
			pq.push({s, 1});
			pq.push({t, -1});
		}
	}
	while(!pq.empty()){
		auto [t, state] = pq.top();
		pq.pop();
		sum += state;
		// cout << t << " " << state << "\n";
		// cout << sum << " ";
		if(sum == 0 && !pq.empty()){
			cout << t << " " << pq.top().s << " ";
			chk = 1;
		}
	}
	if(!chk) cout << -1;
}