Advertisement
serega1112

Brigada

Dec 6th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. n, b, c = map(int, input().split())
  2. heights = []
  3. for i in range(n):
  4.     heights.append(int(input()))
  5. heights.sort()
  6.  
  7. l = -1
  8. r = heights[-1]
  9.  
  10. def check(g, b, c, heights):
  11.     i = 0
  12.     while b:
  13.         if i + c - 1 >= len(heights):
  14.             return False
  15.         if heights[i+c-1] - heights[i] <= g:
  16.             b -= 1
  17.             i = i + c
  18.         else:
  19.             i += 1
  20.     return True
  21.  
  22. while r - l > 1:
  23.     g = l + (r - l) // 2
  24.     if check(g, b, c, heights):
  25.         r = g
  26.     else:
  27.         l = g
  28.  
  29. print(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement