Advertisement
Farz0l1x

Untitled

May 1st, 2024
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. file = open('3A.txt')
  2. N, V, M = map(int, file.readline().split())
  3. a = []
  4. for x in file:
  5.     km, k = map(int, x.split())
  6.     a.append((km, k))
  7. max_con = 0
  8. max_tub = 0
  9. for i in range(N):
  10.     cur_con, cur_tub = 0, 0
  11.     for j in range(N):
  12.         r = abs(a[j][0] - a[i][0])
  13.         if r <= M:
  14.             cur_tub += a[j][1]
  15.             cur_con += (a[j][1] + V - 1) // V
  16.     if cur_tub > max_tub:
  17.         max_tub = cur_tub
  18.         max_con = cur_con
  19. print(max_con)
  20.  
  21. file = open('3B.txt')
  22. N, V, M = map(int, file.readline().split())
  23. a = []
  24. for x in file:
  25.     km, k = map(int, x.split())
  26.     a.append((km, k))
  27. max_con = 0
  28. max_tub = 0
  29. a.sort()
  30. l = r = 0
  31. cur_tub = cur_con = max_tub = max_con = 0
  32. for st in range(N):
  33.     while r < N and a[r][0] - a[st][0] <= M:
  34.         cur_tub += a[r][1]
  35.         cur_con += (a[r][1] + V - 1) // V
  36.         r += 1
  37.     while a[st][0] - a[l][0] > M:
  38.         cur_tub -= a[l][1]
  39.         cur_con -= (a[l][1] + V -1) // V
  40.         l += 1
  41.     if cur_tub > max_tub:
  42.         max_tub = cur_tub
  43.         max_con = cur_con
  44. print(max_con)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement