Submission

Status:

[PPPPP][PPPPP][PPPPPPPPPP]

Subtask/Task Score:

{20/20}{30/30}{50/50}

Score: 100

User: KantaponZ

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

Language: cpp

Time: 0.057 second

Submitted On: 2025-08-25 10:57:55

#include <bits/stdc++.h>
using namespace std;

vector<long long> v(20000001);
int n;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    long long total = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        total += y - x;
        v[x]++; v[y]--;
    }
    if (total == 1) {
        auto it = find(v.begin(), v.end(), 1);
        cout << it - v.begin();
        return 0;
    }
    long long sum = 0;
    for (int i = 0; i <= 20000000; i++) {
        sum += v[i];
        v[i] = sum + (i == 0 ? 0 : v[i - 1]);
    }
    auto it = lower_bound(v.begin(), v.end(), total / 2);
    cout << it - v.begin();
    
}