[Python] [백준 2805] 나무자르기

김바덕·2023년 6월 7일

백준

목록 보기
7/23
post-thumbnail

문제

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


6달전에 풀었던 문제를 오늘 다시 만나게 되었다.
그때보다는 확실히 쉬워진 것 같다!

n,m = list(map(int,input().split()))

array = list(map(int, input().split()))

start = 0
end = max(array)

result = 0
while(start<=end):
    total = 0
    mid = (start+end) // 2

    for i in array:
        if i > mid:
            total += i - mid

    
    if total < m :
        end = mid - 1
    
    else:
        result = mid
        start = mid + 1

print(result)
profile
UXUI Designer

0개의 댓글