Building an Aquarium
EasyRating 1100CodeforcesBinary Search on Answer
Approach hintTry it first, then revealHide
The water needed grows with the tank height h, so binary search the largest h whose total sum(max(0, h - a_i)) stays within x. Use 64-bit sums.