Submission
Status:
[-SSSS][SSSSS][SSSSSSSSSS]
Score: 0
User: Cmoss9
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-12 11:53:50
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<pair<int, int>> books;
long long totalBooks = 0;
// รับค่า Xi และ Yi แล้วเก็บใน books[]
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
books.emplace_back(x, y);
totalBooks += (y - x); // คำนวณจำนวนหนังสือทั้งหมด
}
// หาตำแหน่งมัธยฐาน
long long medianIndex = totalBooks / 2;
long long count = 0;
for (auto [x, y] : books) {
if (count + (y - x) > medianIndex) {
cout << x + (medianIndex - count) << "\n";
return 0;
}
count += (y - x);
}
return 0;
}