Submission
Status:
[PPPPP][PPPPP][PPPPPPPPPP]
Subtask/Task Score:
{20/20}{30/30}{50/50}
Score: 100
User: vachirasawin
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.067 second
Submitted On: 2026-03-12 23:16:04
// grader-chan
// c2_ds66_3m.cpp | c2_ds66_3m
#include <bits/stdc++.h>
using namespace std;
int n;
int x, y;
int curr = 0;
int total = 0, tmp = 0;
vector<int> books(20000001);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
while (n--) {
cin >> x >> y;
books[x]++;
books[y]--;
curr = max(curr, y);
total += y - x;
}
if (total == 1) {
cout << x;
return 0;
}
for (int i = 0; i < curr + 2; i++) {
if (i != 0) books[i] += books[i - 1];
tmp += books[i];
if (tmp >= total / 2) {
cout << i;
return 0;
}
}
return 0;
}