Submission

Status:

[PP-SS][SSSSS][SSSSSSSSSS]

Subtask/Task Score:

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

Score: 0

User: Kitsunox

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

Language: cpp

Time: 0.004 second

Submitted On: 2025-12-16 00:10:53

#include <bits/stdc++.h>

using namespace std;
int n , imd;
vector<pair<int,int>> mp;

bool check(int md){
    int a = 0;
    for(auto [f,b]: mp){
        if(md >= b-1){
            a += b-f;
        }else if(md >= f){
            a += md - f + 1;
        }
    }
    if(a >= imd)return 1;
    return 0;
}

int main(){
    cin >> n;
    int ct = 0;
    for(int i = 0;i < n;i++){
        int a,b; cin >> a >> b;
        mp.push_back({a,b});
        ct += b-a;
    }
    imd = ct /2;
    int l = 0,r = 2e7+7;
    while(l < r){
        int md = (l+r)/2;//cout << r << ' ' << ' ' << md << ' ' << l << '\n';
        if(check(md))r = md;
        else l = md+1;
        
    }
    cout << l;

}