zhukov000

Binary example segments

Nov 15th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. n, k = map(int, input().split())
  2. L = []
  3. for i in range(n):
  4.     L.append(int(input()))
  5.  
  6. if sum(L) < k:
  7.     print(0)
  8. else:
  9.     left = 1
  10.     right = max(L) + 1
  11.    
  12.     while right - left > 1:
  13.         mid = (left + right) // 2
  14.         t = 0
  15.         for x in L:
  16.             t += x // mid
  17.         if t < k:
  18.             right = mid
  19.         else:
  20.             left = mid
  21.     print(left)
Advertisement
Add Comment
Please, Sign In to add comment