Submission
Status:
[PP-SS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: Fifaxmb
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-28 12:23:14
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;
#define Fifa67king ios::sync_with_stdio(0);cin.tie(0);
int main(){
Fifa67king;
int n;cin >> n;
priority_queue<pii, vector<pii>, greater<pii>> pq;
ll c = 0;
for(int i = 0; i < n; i++){
ll a, b; cin >> a >> b;
pq.push({a,1});pq.push({b,-1});
c += b-a;
}
ll target = c/2, cur = 0, prv = -1;
while(!pq.empty()){
auto [pos, d] = pq.top(); pq.pop();
ll bk = cur*(pos-prv);
if(prv!=-1 && cur>0 && target<=bk){
cout << prv+(target-1)/cur;
return 0;
}
if(prv!=-1) target -= bk;
cur += d; prv = pos;
}
}