Submission
Status:
[PPPPP][PPPPP][TSSSSSSSSS]
Subtask/Task Score:
{20/20}{30/30}{0/50}
Score: 50
User: Zonezonee
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 1.121 second
Submitted On: 2025-12-31 12:54:43
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
map<int, int> sweep;
int total = 0, mx = 0, mn =1e9;
for(int i = 0, x, y; i < n; ++i){
cin >> x >> y;
total += y-x;
mx = max(mx, y-1);
mn = min(mn, x);
sweep[x]++;
sweep[y]--;
}
int sum = 0, cnt = 0;
for(int i = mn; i <= mx; ++i){
sum += sweep[i];
cnt += sum;
if(cnt >= total/2){
cout << i << '\n';
return 0;
}
}
}
/*
2
1 7
5 15
*/