(二分枚举) $O(nlog(n))$
二分枚举满足条件的E取最小值
python3 代码
def isValid(e, H):
for h in H:
if h > e:
e -= h - e
else:
e += e - h
if e < 0:
return False
return True
N = int(input())
H = [int(i) for i in input().split()]
l, r, mid = 0, 100000, 0
while l <= r:
mid = (l + r) // 2
if isValid(mid, H):
r = mid - 1
else:
l = mid + 1
print(l)