Submission

Status:

[PPPPP][PPPPP][PPPPPPPPPP]

Subtask/Task Score:

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

Score: 100

User: meme_boi2

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

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-19 17:22:46

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii array <int,2>
int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    int n,sum = 0; cin >> n;
    vector<pii> mat(n);
    for(auto &[x,y]: mat) {
        
        cin >> x >> y;
        sum += y - x;
    }
    int l = 0, r = 2e8;
    if(sum == 1){
        cout << mat[0][0];
        return 0;
    }
    while(l <= r){
        int mid = (l+r)>>1;
        int cnt = 0;
        for(auto [x,y] : mat){
            if(mid >= x){
                cnt += min(mid,y-1) - x + 1;
            }
        }
        if(cnt >= sum/2){
            r = mid - 1;
        }else{
            l = mid +1;
        }
    }
    cout << l;
}
/*
c2_ds66_3m

cd "c:\Users\RICOH-NB110\Desktop\Computer Programing\gchan\" ; if ($?) { g++ c2_ds66_3m.cpp -o c2_ds66_3m } ; if ($?) { .\c2_ds66_3m}
*/