| ps | |
|---|---|
| 링크 | acmicpc.net/… | 
| 출처 | BOJ | 
| 문제 번호 | 2110 | 
| 문제명 | 공유기 배치 | 
| 레벨 | 실버 1 | 
| 분류 | 
 파라메트릭 서치  | 
	
| 시간복잡도 | O(n(logx + logn)) | 
| 인풋사이즈 | n<=200,000, x<=10^9 | 
| 사용한 언어 | Python | 
| 제출기록 | 37392KB / 324ms | 
| 최고기록 | 140ms | 
| 해결날짜 | 2021/06/04 | 
| 태그 | |
"""Solution code for "BOJ 2110. 공유기 설치".
- Problem link: https://www.acmicpc.net/problem/2110
- Solution link: http://www.teferi.net/ps/problems/boj/2110
"""
import sys
from teflib import algorithm
def main():
    def is_impossible(dist):
        count = 1
        prev_pos = x[0]
        for pos in x:
            if pos - prev_pos < dist:
                continue
            prev_pos = pos
            count += 1
            if count >= C:
                return False
        return True
    N, C = [int(x) for x in sys.stdin.readline().split()]
    x = [int(sys.stdin.readline()) for _ in range(N)]
    x.sort()
    upper_bound = (x[-1] - x[0]) // (C - 1) + 2
    print(algorithm.binary_search(1, upper_bound, is_impossible) - 1)
if __name__ == '__main__':
    main()