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
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 5585번 거스름돈(python) (0) | 2021.01.30 |
---|---|
백준 알고리즘 10953번 A + B - 6(python) (0) | 2021.01.28 |
백준 알고리즘 2110번 공유기 설치(python) (0) | 2021.01.28 |
백준 알고리즘 1764번 듣보잡(python) (0) | 2021.01.28 |
백준 알고리즘 10816번 숫자 카드 2(python) (0) | 2021.01.28 |