Problem · Greedy
Maximize Ad-Slot Revenue
Learn this problemProblem statement
You have slots identical advertising slots. Company i requests up to requestedSlots[i] slots and pays revenuePerSlot[i] for each slot it receives.
You may partially fulfill any request. Allocate at most slots total slots and return the maximum revenue. If total demand is smaller than the capacity, unused slots are allowed.
Function
maximizeRevenue(slots: int, requestedSlots: int[], revenuePerSlot: int[]) → longExamples
Example 1
slots = 4requestedSlots = [3,2,4]revenuePerSlot = [5,8,3]return = 26Give two slots to the offer paying 8 and the remaining two to the offer paying 5.
Example 2
slots = 6requestedSlots = [2,3]revenuePerSlot = [4,4]return = 20Only five slots are requested, so one slot remains unused.
Constraints
0 <= slots <= 10^91 <= requestedSlots.length = revenuePerSlot.length <= 1000000 <= requestedSlots[i], revenuePerSlot[i] <= 10^9- The answer fits in a signed 64-bit integer.