Submission
Status:
[PPPPP][PPPPP][PPPPPPPPPP]
Score: 100
User: Nagornz
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-13 20:38:28
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pii pair <int,int>
#define tiii tuple <int, int, int>
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ub(a, b) upper_bound(a.begin(), a.end(), b) - a.begin();
#define lb(a, b) lower_bound(a.begin(), a.end(), b) - a.begin();
#define ve vector
#define graph(a, n) vector <int> a[n];
#define wgraph(a, n) vector <pii> a[n];
#define emb emplace_back
#define em emplace
#define ins insert
#define er erase
#define iShowSpeed cin.tie(NULL)->sync_with_stdio(false)
using namespace std;
template <typename T>
using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int mod = 1e9 + 7;
const int inf = 1e18;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int32_t main(){
iShowSpeed;
int n; cin >> n;
map <int, int> mp;
int sum = 0;
for (int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
mp[x]++;
mp[y]--;
sum += y - x;
}
int idx = sum / 2 == 0 ? 1 : sum / 2;
int cnt = 0;
int curr = 0, prev = 0;
for (auto [x, add] : mp) {
if (cnt + curr * (x - prev) >= idx && curr) {
int wow = idx - cnt;
wow = (wow + curr - 1) / curr;
cout << prev + wow - 1 << "\n";
return 0;
}
cnt += curr * (x - prev);
curr += add;
prev = x;
}
}