풀이시간: 1시간
from bisect import bisect_left, bisect_right
N = int(input())
money = sorted(list(map(int, input().split(' '))))
total_money = int(input())
real_total = sum(money)
if real_total > total_money:
i = -1
while True:
h_money = money[i]
h_money_count = abs(bisect_left(money, h_money) - bisect_right(money, h_money))
have_money = total_money - sum(money[:i - h_money_count + 1])
renew_h_money = int(have_money / -(i - h_money_count + 1))
if len(money) > -(i - h_money_count) and renew_h_money < money[i - h_money_count]:
i -= h_money_count
continue
else:
print(renew_h_money)
break
else:
h_money = max(money)
print(h_money)
N = int(input())
req = list(map(int, input().split()))
M = int(input())
lo = 0
hi = max(req)
mid = (lo + hi) // 2
def is_possible(mid):
return sum(min(r, mid) for r in req) <= M
while lo <= hi:
if is_possible(mid):
lo = mid + 1
ans = mid
else:
hi = mid - 1
mid = (lo + hi) // 2
print(ans)