# 예산 - 프로그래머스

예산 - 프로그래머스

def solution(budgets, M):
    budgets.sort()
    start = 0
    end = max(budgets)
    while start <= end:
        mid = (start + end) // 2
        total = 0
        for ele in budgets:
            if ele <= mid:
                total += ele
            else:
                total += mid
        if total < M:
            start = mid + 1
            limit = mid
        else:
            end = mid - 1
    return limit