Description
You have an inventory of colored balls to sell. The value of a ball is its inventory count. You want to sell exactly n balls. Return the maximum total value that you can attain after selling n balls.
Examples
Input:
inventory = [2,5], orders = 4Output:
14Explanation:
Greedy: sell highest value balls first. Ball worth 5, then 4, then 3, then 2. Total: 5+4+3+2=14.
Input:
inventory = [3,5,1], orders = 6Output:
19Explanation:
Selling the highest-valued balls greedily gives a total of 19, so the answer is 19.
Input:
inventory = [1000000], orders = 3Output:
2999997Explanation:
There are one type of ball with inventory count 1000000. Selling 3 balls with values 1000000, 999999, and 999998. Total: 1000000 + 999999 + 999998 = 2999997.
Constraints
- •
1 ≤ inventory.length ≤ 10^5 - •
1 ≤ orders ≤ min(sum(inventory), 10^9)