본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 2512번 예산

by 현장 2022. 5. 6.

-Code

n = int(input())
parts = list(map(int, input().split()))
total_max = int(input())
start, end = 0, total_max
if sum(parts) <= total_max:
    print(max(parts))
else:
    while start <= end:
        mid = (start + end) // 2
        total = 0
        for i in parts:
            if mid < i:
                total += mid
            else:
                total += i
        if total <= total_max:
            start = mid + 1
        else:
            end = mid - 1
    print(end)