Maximize Fish over Limited Hours
Problem statement
You are given initial hourly fish yields yields for several ponds and a number of fishing hours hours. In each hour, choose exactly one pond, collect its current yield, and decrease that pond's future yield by one without going below zero.
Return the maximum total fish that can be collected. Your solution should aggregate yield levels instead of simulating every hour with a heap.
Function
maximizeFish(yields: int[], hours: long) → longExamples
Example 1
yields = [90,100]hours = 100return = 7075The optimal schedule always takes a currently largest yield; aggregating the top one hundred available positive yields gives 7075.
Example 2
yields = [2,1]hours = 5return = 4The positive collections are 2, 1, and 1; remaining hours contribute zero.
Constraints
1 <= yields.length <= 2000000 <= yields[i] <= 10000000001 <= hours <= 100000000000000- The answer fits signed 64-bit arithmetic.