Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from random import *
- from itertools import permutations
- from math import gcd
- input = lambda: sys.stdin.readline().strip()
- def mas():
- return list(map(int, input().split()))
- f = open("27_B_5142 (1).txt")
- n, m = map(int, f.readline().split())
- a = []
- for i in range(n):
- x, y = map(int, f.readline().split())
- z = (y + 49) // 50
- a.append([x, y, z])
- a.sort()
- pref_y = [0] * (n + 1)
- pref_z = [0] * (n + 1)
- for i in range(1, n + 1):
- pref_y[i] = pref_y[i - 1] + a[i - 1][1]
- pref_z[i] = pref_z[i - 1] + a[i - 1][2]
- ans = -1
- z = -1
- for i in range(n):
- l = -1
- r = i
- while r - l > 1:
- mid = (l + r) >> 1
- if a[i][0] - a[mid][0] <= m:
- r = mid
- else:
- l = mid
- ind1 = r
- l = i
- r = n
- while r - l > 1:
- mid = (l + r) >> 1
- if a[mid][0] - a[i][0] <= m:
- l = mid
- else:
- r = mid
- ind2 = l
- if pref_y[ind2 + 1] - pref_y[ind1] > ans:
- ans = pref_y[ind2 + 1] - pref_y[ind1]
- z = pref_z[ind2 + 1] - pref_z[ind1]
- elif pref_y[ind2 + 1] - pref_y[ind1] == ans and pref_z[ind2 + 1] - pref_z[ind1] < z:
- z = pref_z[ind2 + 1] - pref_z[ind1]
- print(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement