Agorithm/백준 알고리즘
백준 알고리즘 1654번 랜선 자르기(python)
kimjinho1
2021. 1. 28. 12:16
728x90
반응형
이분 탐색 문제이다. 2110번 공유기 설치와 비슷한 문제다.
def count(li, m):
cnt = 0
for n in li:
cnt += (n // m)
return cnt
def binarySearch(li, K):
s, e = 1, max(li)
while s <= e:
m = (s + e) // 2
if count(li, m) >= K:
ans = m
s = m + 1
else:
e = m - 1
return ans
N, K = map(int, input().split())
li = sorted([int(input()) for _ in range(N)])
print(binarySearch(li, K))
728x90
반응형