Advertisement
nq1s788

26 коробки на доразбор

May 17th, 2025
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. data = open('26.txt').readlines()
  2. n, k, Q = map(int, data[0].split())
  3. a = []
  4. for e in data[1:]:
  5.     a.append(tuple(map(int, e.split())))
  6. a.sort()
  7. inf = 1000000000
  8. mx_s = a[-1][0]
  9. dp = [[inf for j in range(Q + 1)] for i in range(mx_s + 1)]
  10. cur_a = 0
  11. mn = inf
  12. for s in range(1, mx_s + 1):
  13.     if s < a[cur_a][0]:
  14.         continue
  15.     if cur_a != n and s == a[cur_a + 1][0]:
  16.         cur_a += 1
  17.     dp[s][1] = min(mn, a[cur_a][1])
  18.     mn = dp[s][1]
  19. for q in range(2, Q + 1):
  20.     cur_a = 0
  21.     mn = inf
  22.     for s in range(1, mx_s + 1):
  23.         if a[cur_a][0] - k < a[0][0] or dp[a[cur_a][0] - k] :
  24.             continue
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement