import sys
input = sys.stdin.readline
N = int(input())
budgets = list(map(int, input(), split()))
M = int(input())
if sum(budgets) <= M:
print (max(budgets))
exit()
low = 0
high = max(budgets)
answer = 0
while low <= high:
mid = (low+high)//2
total = 0
for b in budgets:
total +=min(b,mid)
if total<= M:
answer = mid
low = mid + 1
else:
high = mid - 1
print(answer)
To embed this project on your website, copy the following code and paste it into your website's HTML: