Submission
Status:
[PPPPP][PPPPP][PPPPPPPPPP]
Score: 100
User: njoop
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.202 second
Submitted On: 2025-03-09 23:39:27
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, l, r, cnt[20000010], book[20000010], dif, to;
vector<int> books;
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1; i<=n; i++) {
cin >> l >> r;
cnt[l]++;
cnt[r]--;
to += r-l;
}
book[0] = cnt[0];
dif = cnt[0];
if(book[0] > to/2-1 && book[0] != 0) {
cout << 0;
return 0;
}
for(int i=1; i<=20000000; i++) {
dif += cnt[i];
book[i] = book[i-1] + dif;
if(to == 1 && cnt[i] == 1) {
cout << i;
return 0;
}
if(book[i-1] <= to/2-1 && book[i] > to/2-1) {
cout << i;
return 0;
}
}
return 0;
}