Submission

Status:
[P-SSS][SSSSS][SSSSSSSSSS]

Score: 0

User: Nakornrat

Problemset: ห้องสมุดเมือง 3M

Language: cpp

Time: 0.002 second

Submitted On: 2025-03-19 17:04:04

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin >> n;
    
    vector<pair<int, int>> books;
    long long total_books = 0;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        books.emplace_back(x, y);
        total_books += (y - x);
    }

    long long median_pos = total_books / 2;
    long long count = 0;
    
    for (const auto& range : books) {
        int x = range.first, y = range.second;
        if (count + (y - x) > median_pos) {
            cout << x + (median_pos - count) - 1 << endl;
            return 0;
        }
        count += (y - x);
    }

    return 0;
}