Submission

Status:

[PPPPP][PPPPP][PPPPPPPPPP]

Subtask/Task Score:

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

Score: 100

User: Zonezonee

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

Language: cpp

Time: 0.014 second

Submitted On: 2025-12-31 12:56:02

#include <bits/stdc++.h>
using namespace std;
const int N = 2e7+10;

int sweep[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int total = 0, mx = 0, mn =1e9;
    for(int i = 0, x, y; i < n; ++i){
        cin >> x >> y;
        total += y-x;
        mx = max(mx, y-1);
        mn = min(mn, x);
        sweep[x]++;
        sweep[y]--;
    }
    int sum = 0, cnt = 0;
    for(int i = mn; i <= mx; ++i){
        sum += sweep[i];
        cnt += sum;
        if(cnt >= total/2){
            cout << i << '\n';
            return 0;
        }
    }
}
/*
2
1 7
5 15
*/