Submission
Status:
[P-SSS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: Few500
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-21 19:48:09
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
long long total = 0;
vector<pair<int, int>> library(n);
for(int i=0; i<n; i++){
cin >> library[i].first >> library[i].second;
total += library[i].second - library[i].first;
}
int l = 0, r = 2e8;
while(l < r){
int mid = (l + r) >> 1;
long long cnt = 0;
for(auto [start, end] : library){
if(start <= mid)
cnt += min(mid, end - 1) - start + 1;
}
if(cnt >= total / 2)
r = mid - 1;
else
l = mid + 1;
}
cout << l << '\n';
return 0;
}