Trains the technique from
LeetCode 2861Maximum Number of AlloysThis 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 print shop is quoting a run of identical posters. It keeps inks different inks, numbered 0 to inks - 1, and presses presses, numbered 0 to presses - 1.
Press i is plumbed for its own mix: turning out one poster on it consumes exactly recipe[i][j] grams of ink j, for every ink j. The shop already holds onhand[j] grams of ink j, which cost nothing to use, and it can order any whole number of extra grams of ink j at price[j] per gram. The total order may cost at most budget.
The whole run has to come off a single press; posters cannot be split between presses. Ink left over is simply left over, and it can never be sold or traded towards the cost of a different ink.
Return the largest number of posters the shop can turn out.
Example 1
Press 1 turns out seven posters: it needs 7 grams of ink 0 and 21 of ink 1, so the shop orders 1 gram of ink 0 for 4 and 13 grams of ink 1 for 26, spending 30 in total.
Example 2
Nothing can be ordered, so the run is capped by the ink already in the cupboard; ink 1 runs out first at three posters.
Example 3
Ink 0 is plentiful and ink 1 is bare, so every poster needs a gram of ink 1 ordered at 2, and the budget of 6 covers three of them.
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 most_posters(inks: int, presses: int, budget: int, recipe: list[list[int]], onhand: list[int], price: list[int]) -> int:public int mostPosters(int inks, int presses, int budget, List<List<Integer>> recipe, List<Integer> onhand, List<Integer> price)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.