본문 바로가기

알고리즘/백준 (Pyhthon)

[알고리즘] 백준 2110 공유기 설치

 

n, c = map(int, input().split(" "))

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

start = location[1] - location[0]
end = location[-1] - location[0]
ans = 1

while start <= end:
    gap = (start+end) // 2
    value = location[0]
    count = 1
    for i in range(1,len(location)):
        if value + gap <= location[i]:
            count += 1
            value = location[i]
    
    if count >= c:
        start = gap + 1
        ans = gap
    else:
        end = gap -1
        
print(ans)