문제


풀이

def solution(distance, rocks, n):
    rocks.append(distance)
    rocks = sorted(rocks)
    left = 0
    right = rocks[-1]
    answer = 0

    while left<=right:
        mid = int((left+right)/2)

        prev = 0
        cnt = 0
        betweenList =[]
        for x in rocks:
            between = x-prev
            if between<mid:
                cnt += 1
            else:
                prev = x
                betweenList.append(between)
        betweenMin = min(betweenList)

        if cnt>n:
            right = mid-1
        else:
            if answer<betweenMin:
                answer = betweenMin
            left = mid+1
    return answer


Reference

https://contest.usaco.org/DEC06.htm