백준 2110 - 공유기 설치 (파이썬)
Updated:
Answer
import sys
n, c = map(int, sys.stdin.readline().split())
a = sorted([int(sys.stdin.readline()) for _ in range(n)])
s, e = 1, max(a) - 1
def calculate(m):
tmp = 1
wifi = a[0] + m
for i in range(1, n):
if a[i] >= wifi:
tmp += 1
wifi = a[i] + m
return tmp
while s <= e:
m = (s + e) // 2
tmp = calculate(m)
if tmp >= c:
s = m + 1
elif tmp < c:
e = m - 1
print(e)