
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Let's note that the altitude of an element is the sum of gains of all the elements behind it
Getting the altitudes can be done by getting the prefix sum array of the given array