๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/boj

BOJ 1654 - ๋žœ์„  ์ž๋ฅด๊ธฐ

by HandHand 2021. 3. 18.

๋ฌธ์ œ

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ - 1654๋ฒˆ

ํ’€์ด ๊ณผ์ •

๋žœ์„ ๋“ค์„ ์ผ์ •ํ•œ ํฌ๊ธฐ๋กœ ์ž˜๋ž์„ ๋•Œ ์›ํ•˜๋Š” ๊ฐœ์ˆ˜๋ฅผ ๋งŒ์กฑํ•˜๋Š” ์ตœ๋Œ€ ๊ธธ์ด๋ฅผ ์ฐพ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

๋žœ์„  ๊ธธ์ด์˜ ์ƒํ•œ๊ณผ ํ•˜ํ•œ์„ ๊ฒฐ์ •ํ•œ ๋’ค ์ด๋ถ„ ํƒ์ƒ‰ ์„ ํ†ตํ•ด ์•Œ๋งž์€ ๊ธธ์ด๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋žœ์„  ๊ธธ์ด์˜ ์ƒํ•œ์€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋žœ์„  ์ค‘ ๊ฐ€์žฅ ๊ธด ๊ฐ’์ด๊ณ  ํ•˜ํ•œ์€ 1๋กœ ์„ค์ •ํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys


K, N = list(map(int, sys.stdin.readline().split()))
lines = []
for _ in range(K):
    lines.append(int(input()))


def enough(cut):
    ret = 0
    for line in lines:
        ret += line // cut
    return True if ret >= N else False


def solution():
    lo = 1
    hi = max(lines)

    answer = 0
    while lo <= hi:
        mid = (lo + hi) // 2
        if enough(mid):
            answer = mid
            lo = mid + 1
        else:
            hi = mid - 1

    return answer


print(solution())
๋ฐ˜์‘ํ˜•

๐Ÿ’ฌ ๋Œ“๊ธ€