Submission
Status:
[P-SSS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: Shangbin
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-12 12:29:03
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int maxn = 100;
int n, x, y, num_count = 0;
vector<pii> range;
int getIndex(int val){
int result = 0;
for (auto [cx, cy] : range){
if (val >= cy) result += (cy - cx);
else {
result += (val - cx) + 1;
break;
}
}
return result;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(0);
cin >> n;
int max_y = 0;
for (int i = 0; i < n; i++){
cin >> x >> y;
range.push_back({x, y});
num_count += (y - x);
max_y = max(max_y, y);
}
int l = 0, r = max_y;
while (l < r){
int mid = (l+r)/2;
if (getIndex(mid) < num_count/2) l = mid+1;
else r = mid;
}
cout << l;
}