Submission
Status:
[P-SSS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: Seng
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.003 second
Submitted On: 2026-05-26 21:07:36
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;cin >> n;
int cnt = 0;
priority_queue<pii, vector<pii>, greater<pii>> pq;
while(n--){
int x, y;cin >> x >> y;
cnt += y-x;
pq.push({x, 1});
pq.push({y, -1});
}
int ss = cnt/2;
int sum = 0;
int add = 0;
while(!pq.empty()){
auto [f, l] = pq.top();
//cout << f << " " << l << " " << sum << '\n';
pq.pop();
add += l;
sum += (pq.top().first-f)*add;
if(sum >= ss){
int x = sum-ss;
int y = pq.top().first-f;
int z = y-x;
cout << f+z-1;
return 0;
}
}
}