算法1
(二分) $O(nlogn)$
上界是1e9+1e9=2e9 最小是原数组中位数
二分即可
python 代码
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
l, r = arr[n//2], 2e9
def check(m):
res = 0
for i in range(n//2, n):
if arr[i] < m:
res += (m-arr[i])
return res<=k
while l<r:
mid = (l+r+1)//2
if check(mid):
l = mid
else:
r = mid - 1
print(int(r))