Submission
Status:
[-SSSS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: winniecoder1029
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-04 22:34:32
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
if (!(cin >> n)) return 0;
long long amount = 0;
vector<long long> x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
amount += (y[i] - x[i]);
}
long long target = amount / 2;
long long pivot = 0;
// 2^25 = 33,554,432 (Covers the 20,000,000 limit)
for (long long step = 33554432; step > 0; step /= 2) {
long long testPivot = pivot + step;
long long Lbook = 0;
for (int i = 0; i < n; i++) {
if (x[i] < testPivot) {
// Count elements in [x[i], y[i]) that are < testPivot
Lbook += min(y[i], testPivot) - x[i];
}
}
if (Lbook <= target) {
pivot += step;
}
}
cout << pivot << endl;
return 0;
}