Submission

Status:

[PPPPP][PPPPP][PPPPPPPPPP]

Subtask/Task Score:

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

Score: 100

User: Nay-O

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

Language: cpp

Time: 0.008 second

Submitted On: 2026-03-15 21:28:24

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

const int N = 2e8+5;

priority_queue<pii, vector<pii>, greater<pii>> pq;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n; cin >> n;
    int c =0;
    for(int i=0; i < n; i++){
        int a, b;
        cin >>a>>b;
        pq.push({a,1});
        pq.push({b,-1});
        c+=b-a;
    }
    
    int a = c/2;
    
    ll sum =0;
    int b =0;
    
	while(!pq.empty()){
		b+=pq.top().second;
		int x = pq.top().first;
		pq.pop();
		for(int i = x; i < pq.top().first; i++){
			sum+=b;
			if(sum>=a){
				cout << i;
				return 0;
			}
		}
		
	}
    
    return 0;
}