Maximize Revenue from Decreasing Inventory
Problem statement
A shop stocks several item types. The integer quantities[i] is the remaining inventory of type i. Selling one item from a type earns its current remaining quantity, then reduces that quantity by one.
Exactly customers customers each buy one item. Choose the item type for every sale to maximize total revenue. Return that maximum revenue.
Function
maximizeRevenue(quantities: int[], customers: int) → longExamples
Example 1
quantities = [2,5]customers = 4return = 14Sell from remaining quantities 5, 4, 3, and 2 for total revenue 14.
Example 2
quantities = [3,3]customers = 3return = 8The best sale prices are 3, 3, and 2.
Constraints
1 <= quantities.length <= 100000.1 <= quantities[i] <= 1000000.1 <= customers <= 1000000.customers <= sum(quantities).- The answer fits in a signed 64-bit integer.