Submission
Status:
[P-SSS][SSSSS][SSSSSSSSSS]
Score: 0
User: dwad2
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-20 20:36:14
#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++) {
cin >> libraries[i].first >> libraries[i].second;
total_books += (libraries[i].second - libraries[i].first);
}
sort(libraries.begin(), libraries.end());
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) - 1 << endl;
return 0;
}
count += books_in_range;
}
return 0;
}