257일차 - BOJ no.2110

https://www.acmicpc.net/problem/2110

My Solution

n, c = list(map(int, input().split(' ')))

arr = []
for _ in range(n):
    arr.append(int(input()))
arr.sort()

def install_router(lst, C):
    lst.sort()

    lo = 1
    hi = lst[-1] - lst[0]
    min_gap = 0

    while lo <= hi:
        mid = (lo + hi) // 2
        cnt = 1
        cur = lst[0]

        for i in range(1, len(lst)):
            if lst[i] >= cur + mid:
                cur = lst[i]
                cnt += 1

        if cnt >= C:
            min_gap = mid
            lo = mid + 1
        else:
            hi = mid - 1

    return min_gap

print(install_router(arr, c))

좋은 웹페이지 즐겨찾기