book = [10, 20, 15, 18]
M = 12

left = 0
right = max(book)
answer = 0

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

    total = 0
    for i in book:
        if i > mid:
            total += i - mid

    if total >= M:
        answer = mid
        left = mid + 1
    else:
        right = mid - 1

print(answer)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: