Submission
Status:
[-SSSS][SSSSS][SSSSSSSSSS]
Score: 0
User: dwad2
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-20 20:27:39
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> libraries(n);
long long total_books = 0;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
libraries[i] = {x, y};
total_books += (y - x);
}
long long medianIndex = total_books / 2;
long long count = 0;
for (auto [x, y] : libraries) {
long long books_in_range = y - x;
if (count + books_in_range > medianIndex) {
cout << x + (medianIndex - count) << endl;
return 0;
}
count += books_in_range;
}
return 0;
}