-
2110번: 공유기 설치
첫째 줄에 집의 개수 N (2 ≤ N ≤ 200,000)과 공유기의 개수 C (2 ≤ C ≤ N)이 하나 이상의 빈 칸을 사이에 두고 주어진다. 둘째 줄부터 N개의 줄에는 집의 좌표를 나타내는 xi (0 ≤ xi ≤ 1,000,000,000)가
www.acmicpc.net
코드
import sys N, C = map(int, (input().split())) house = [int(sys.stdin.readline()) for _ in range(N)] house = sorted(house) start, end = 1, house[-1] - house[0] def router_counter(distance): count = 1 cur_house = house[0] for i in range(1, N): if cur_house + distance <= house[i]: count += 1 cur_house = house[i] return count while start <= end: mid = (start+end) // 2 if router_counter(mid) >= C: answer = mid start = mid + 1 else: end = mid - 1 print(answer)
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 11279번 최대 힙 (파이썬) (0) 2022.01.04 [백준] 12015번 가장 긴 증가하는 부분 수열 2 (파이썬) (0) 2022.01.02 [백준] 2805번 나무 자르기 (파이썬) (0) 2022.01.02 [백준] 1654번 랜선 자르기 (파이썬) (0) 2022.01.02 [백준] 10816번 숫자 카드 2 (파이썬) (0) 2022.01.02