Submission

Status:

[PP-SS][SSSSS][SSSSSSSSSS]

Subtask/Task Score:

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

Score: 0

User: KantaponZ

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

Language: cpp

Time: 0.056 second

Submitted On: 2025-08-25 00:47:22

#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]--;
    }
    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();
    
}

/*
3
1 3
1 3
3 4


*/