Submission
Status:
[PPPPP][PPPPP][PPPPPPPPPP]
Score: 100
User: Cmoss9
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.009 second
Submitted On: 2025-03-23 17:13:53
#include <bits/stdc++.h>
using namespace std;
int main () {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n;
cin >> n;
vector<pair<int,int>> books;
int sum = 0;
for (int i = 0;i<n;i++) {
int a,b;
cin >> a >> b;
books.push_back({a,1});
books.push_back({b,-1});
sum += b-a;
}
sort(books.begin(), books.end());
int median = sum/2;
int index = 0;
int lvl = 0;
int count = 0;
while (true) {
int current = books[index].first;
while (current == books[index].first) {
int value = books[index].second;
lvl += value;
index++;
}
while (current < books[index].first) {
count += lvl;
if (count >= median) {
cout << current;
return 0;
}
current++;
}
}
}