Class Solution
-
- All Implemented Interfaces:
public final class Solution1648 - Sell Diminishing-Valued Colored Balls\.
Medium
You have an
inventoryof different colored balls, and there is a customer that wantsordersballs of any color.The customer weirdly values the colored balls. Each colored ball's value is the number of balls **of that color **you currently have in your
inventory. For example, if you own6yellow balls, the customer would pay6for the first yellow ball. After the transaction, there are only5yellow balls left, so the next yellow ball is then valued at5(i.e., the value of the balls decreases as you sell more to the customer).You are given an integer array,
inventory, whereinventory[i]represents the number of balls of the <code>i<sup>th</sup></code> color that you initially own. You are also given an integerorders, which represents the total number of balls that the customer wants. You can sell the balls in any order.Return the maximum total value that you can attain after selling
orderscolored balls. As the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.Example 1:
Input: inventory = 2,5, orders = 4
Output: 14
Explanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3). The maximum total value is 2 + 5 + 4 + 3 = 14.
Example 2:
Input: inventory = 3,5, orders = 6
Output: 19
Explanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2). The maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.
Constraints:
<code>1 <= inventory.length <= 10<sup>5</sup></code>
<code>1 <= inventoryi<= 10<sup>9</sup></code>
<code>1 <= orders <= min(sum(inventoryi), 10<sup>9</sup>)</code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-