Trains the technique from
LeetCode 1648Sell Diminishing-Valued Colored BallsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A poster archive prices reprints by scarcity. stacks[i] is how many copies of design i are left in the drawer, and a copy of a design that still has k copies in the drawer sells for exactly k credits, after which that design has k - 1 copies left.
A wholesaler has paid for orders copies in total and does not care which designs they come from, so you choose the design each copy is drawn from, one copy at a time.
Return the largest total number of credits the archive can take in, modulo 10^9 + 7.
Example 1
Draw from design 1 at 5, 4 and 3 credits, then from design 0 at 2 credits, for 14 credits in total.
Example 2
Draw from design 1 at 5 and 4 credits, then from design 0 at 3 credits, then design 1 at 3, then design 0 at 2, then design 1 at 2, for 19 credits.
Example 3
Draw one copy of each design at 4 credits, then two more copies at 3 credits each, for 18 credits.
Example 4
Only one design exists, so its copies go at 7, 6, 5, 4, 3, 2 and 1 credits.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_profit(stacks: list[int], orders: int) -> int:public int maxProfit(int[] stacks, int orders)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.