Skip to content

Instantly share code, notes, and snippets.

@flutesa
Created December 9, 2013 15:42
Show Gist options
  • Save flutesa/7874153 to your computer and use it in GitHub Desktop.
Save flutesa/7874153 to your computer and use it in GitHub Desktop.
def isAnswer(array, k, checked):
last = -1
count = 0
for i in range(len(array)):
if last == -1 or array[i] - array[last] >= checked:
count += 1
last = i
return count >= k
def find(array, k):
l = 0
r = 10**9
while l + 1 < r:
m = (l + r)//2
if isAnswer(array, k, m):
l = m
else:
r = m
return l
n, k = list(map(int, input().split()))
st_array = list(map(int, input().split()))
print(find(st_array, k))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment