BOJ - 2805 - 나무 자르기

Updated:

import sys

def solution():
    N, M = map(int, sys.stdin.readline().split())
    treeList = list(map(int, sys.stdin.readline().split()))

    left = 1
    right = max(treeList)
    ret = 0

    while left <= right:
        count = 0
        mid = (left + right) // 2

        for tree in treeList:
            if tree - mid > 0:
                count += tree - mid

        if count < M:
            right = mid - 1
        else:
            if ret < mid:
                ret = mid
            left = mid + 1

    print(ret)
solution()

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

Categories:

Updated:

Leave a comment