Egor_1425

Untitled

Jul 27th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. n, k = map(int, input().split())
  2. *a, = map(int, input().split())
  3. a.sort()
  4. left = 0
  5. right = a[-1] - a[0] + 1
  6. while left < right:
  7.     mid = (left + right)//2
  8.     cows = 1
  9.     last = a[0]
  10.     for cur in a[1:]:
  11.         if cur - last > mid:
  12.             cows += 1
  13.             last = cur
  14.     if cows >= k:
  15.         left = mid+1
  16.     else:
  17.         right = mid
  18. print(left)
Add Comment
Please, Sign In to add comment