2025年6月12日 星期四

基地台

 def isCover(d):

  dc  = 1

  left = ps[0]

  right = left + d

  for p in ps[1:]:

    if p>right:

      dc +=1

      left = p

      right = left +d 

      if dc > k:

        return False

  return True


n,k = map(int,input().split())

ps =sorted( [int(i) for i in input().split()])


low = 1

high = ps[-1]-ps[0]


while low<=high:

  m = (high-low)//2 + low

  if isCover(m):

    high = m -1

  else:

    low = m + 1

print(low)


data

5 2

1 2 5 7 8


Output:

3

沒有留言:

張貼留言