본문 바로가기
  • KEEP HUSTLE!
파이썬 코테 준비

[백준 2110] 공유기 설치 - Python(파이썬)

by 하수군 2021. 2. 20.
import sys

N, C = map(int, sys.stdin.readline().split())
houses = []

for n in range(N):
    houses.append(int(sys.stdin.readline().strip()))

houses.sort()
start, end = 1, houses[-1] - houses[0]
ans = 0

while start <= end:
    gap = (start + end) // 2
    x = houses[0]
    cnt = 1
    for i in range(1, N):
        if houses[i] >= x + gap:
            cnt += 1
            x = houses[i]
    if cnt >= C:
        start = gap + 1
        ans = gap
    else:
        end = gap - 1
print(ans)

댓글