Submission
Status:
[PP-SS][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-07 06:16:54
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
int mid = 0;
map<int, int> diff;
for (int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
diff[x]++;
diff[y]--;
mid += y-x;
}
mid /= 2;
int cnt = 0;
int prev = 0;
int pfs = 0;
for (auto i : diff) {
int now = i.first;
cnt += (now - prev) * pfs;
if (cnt >= mid) {
cnt -= (now - prev) * pfs;
for (int j = prev; j < now; ++j) {
cnt += pfs;
if (cnt >= mid) {
cout << j;
return 0;
}
}
}
prev = now;
pfs += i.second;
}
return 0;
}