Submission
Status:
[-SSSS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: tHeNyXs
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-06 20:37:59
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector<pair<int,int>> ev;
ll total = 0;
for(int i=0;i<n;i++){
int x,y; cin >> x >> y;
ev.push_back({x,1});
ev.push_back({y,-1});
total += y-x;
}
sort(ev.begin(),ev.end());
ll mid = total/2;
ll active = 0;
for(int i=0;i<ev.size()-1;i++){
active += ev[i].second;
ll len = (ll)active * (ev[i+1].first - ev[i].first);
if(mid <= len){
cout << ev[i].first + mid/active;
return 0;
}
mid -= len;
}
}