Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Pair {
- int m, h;
- } a[100500];
- bool cmp(Pair p1, Pair p2) {
- return p1.m < p2.m;
- }
- int main() {
- cin >> n >> d;
- for (int i = 1; i <= n; i++)
- cin >> a[i].m >> a[i].h;
- sort(a + 1, a + n + 1, cmp);
- for (int i = 1; i <= n; i++)
- d[i] = d[i - 1] + a[i].h;
- for (int i = 1; i <= n; i++) {
- l = i;
- r = n;
- pos = -1;
- while(l <= r) {
- int mid = (l + r) / 2;
- if (a[mid].m - a[i].m < d) {
- pos = mid;
- l = mid + 1;
- }
- else
- r = mid - 1;
- }
- if (pos == -1)
- ans = max(ans, a[i].h);
- else
- ans = max(ans, d[pos] - d[i - 1]);
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement