Maximum Boat Distance with Resting Energy
Problem statement
A boat starts with energy k. On day i, it may move only with positive energy, gaining wind[i] distance and losing one energy, or rest, gaining one energy up to the cap k.
Wind may be negative. Return the maximum total distance after all days without allowing energy below zero. Resting is always allowed, so the answer is at least zero.
Function
maximumBoatDistance(k: int, wind: int[]) → longExamples
Example 1
k = 2wind = [5,1,10]return = 15Moving on days one and three after resting on day two yields fifteen.
Example 2
k = 1wind = [-5,-2]return = 0Rest every day for zero distance.
Example 3
k = 0wind = [4,5]return = 0With zero energy the boat cannot move.
Constraints
0 <= k < 1000.0 <= wind.length <= 100000.- The answer fits in a signed 64-bit integer.