Submission

Status:

[P-SSS][SSSSS][SSSSSSSSSS]

Subtask/Task Score:

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

Score: 0

User: Shangbin

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

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-13 23:45:17

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int maxn = 100, inf = 1e9;
int n, x, y, num_count = 0;
vector<pii> range;

int getIndex(int val){
    int result = 0;
    for (auto [cx, cy] : range){
        if (val >= cy) result += (cy - cx);
        else {
            result += (val - cx) + 1;
            break;
        }
    }
    return result;
}
    
int main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    cin >> n;
    int max_y = 0, min_x = 1e9;
    for (int i = 0; i < n; i++){
        cin >> x >> y;
        range.push_back({x, y});
        num_count += (y - x);
        max_y = max(max_y, y);
        min_x = min(min_x, x);
    }
    int l = min_x, r = max_y;
    while (l < r){
        int mid = (l+r)/2;
        if (getIndex(mid) < num_count/2) l = mid+1;
        else r = mid;
    }
    cout << l;
}