Advertisement
serega1112

Korovy

Jan 23rd, 2022
958
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n, k = map(int, input().split())
  2. coords = list(map(int, input().split()))
  3.  
  4. l = 1
  5. r = coords[-1]
  6.  
  7. def check(dist, k, coords):
  8.     count = 1
  9.     to_prev = 0
  10.     for i in range(1, len(coords)):
  11.         to_prev += coords[i] - coords[i-1]
  12.         if to_prev >= dist:
  13.             count += 1
  14.             to_prev = 0
  15.     return count >= k
  16.  
  17.  
  18. while r - l > 1:
  19.     mid = l + (r - l) // 2
  20.     if check(mid, k, coords):
  21.         l = mid
  22.     else:
  23.         r = mid
  24.  
  25. print(l)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement