Tap here to switch tabs
Problem
Submissions

Problem: Sell Diminishing-Valued Colored Balls

Sell Diminishing-Valued Colored Balls gives color inventories and orders, asking for the maximum sales value as each sale lowers that color's future value. Return it modulo a large prime.

Statement

You are given an integer array inventory, where inventory[i] represents the initial number of balls of the iith color. You are also given an integer orders, representing the total number of balls to sell.

The value of each ball depends on the number of remaining balls of that color. Specifically, selling a ball of a color that currently has kk balls remaining yields a value of kk, after which the count of balls of that color decreases by 11.

Return the maximum total value that can be achieved after selling orders balls. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq inventory.length ≤105\leq 10^5

  • 1≤1 \leq inventory[i] ≤109\leq 10^9

  • 1≤1 \leq orders ≤min⁡(∑\leq \min(\suminventory[i],109), 10^9)

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sell Diminishing-Valued Colored Balls

Sell Diminishing-Valued Colored Balls gives color inventories and orders, asking for the maximum sales value as each sale lowers that color's future value. Return it modulo a large prime.

Statement

You are given an integer array inventory, where inventory[i] represents the initial number of balls of the iith color. You are also given an integer orders, representing the total number of balls to sell.

The value of each ball depends on the number of remaining balls of that color. Specifically, selling a ball of a color that currently has kk balls remaining yields a value of kk, after which the count of balls of that color decreases by 11.

Return the maximum total value that can be achieved after selling orders balls. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq inventory.length ≤105\leq 10^5

  • 1≤1 \leq inventory[i] ≤109\leq 10^9

  • 1≤1 \leq orders ≤min⁡(∑\leq \min(\suminventory[i],109), 10^9)