시작이 반

[백준] 1654번번 (python 파이썬) 본문

카테고리 없음

[백준] 1654번번 (python 파이썬)

G_Gi 2021. 3. 17. 01:27
SMALL

https://www.acmicpc.net/problem/1654

 

첫번째 풀이(실패)

k, n = map(int, input().split(' '))
lans = [int(input()) for _ in range(k)]

min_lan = min(lans)

result = list()

def binary():
    global min_lan
    left = 1
    right = min_lan
    prev = (left + right) // 2
    while left <= right:
        count = 0

        for lan in lans:
            count += lan // min_lan

        if count == n:
            if min_lan in result:
                break
            else:
                result.append(min_lan)

        mid = (left + right) // 2

        if count < n:
            right = mid
            min_lan = mid
        elif count >= n:
            left = mid
            right = prev
            min_lan = (left + right) // 2

binary()
print(max(result))

 

최종 풀이

k, n = map(int, input().split(' '))
lans = [int(input()) for _ in range(k)]

result = list()


def binary():
    left = 1
    right = max(lans)
    while left <= right:
        count = 0
        mid = (left + right) // 2

        for lan in lans:
            count += lan // mid

        if count < n:
            right = mid - 1
        elif count >= n:
            left = mid + 1

    return right


print(binary())

 

 

LIST