Can anyone kindly give me some hint on solving this?
There are $n$ water containers placed on the top of each other (container1 on top of container2, container2 on top of container3, ...), each with capacity $c_i$ and initial water $a_i$ ($a_i<c_i$). In case of breakage of any container, all the water inside it will pour into the container below. Each container will break if the water inside it is more than its capacity. On the other hand, we can always break a container manually by paying the cost $p_i$.
Provide an algorithm to find the minimum cost to break the $n$th container in $O(n\log n)$. Using a binary heap may be useful.