Submission
Status:
[PPPPP][PPPPP][PPPPPPPPPP]
Subtask/Task Score:
{20/20}{30/30}{50/50}
Score: 100
User: Seng
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.006 second
Submitted On: 2026-05-26 21:11:52
#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;
for(int i = f; i < pq.top().first; i++){
sum += add;
if(sum >= ss){
cout << i;
return 0;
}
}
}
}