All problems
0938MediumArrayDynamic ProgrammingGreedy

Most Units Bought From the Bundle Sale

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3946Maximum Number of Items From Sale I

This 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 sale lists its lines as items, where items[i] is [factor, price].

Line i is sold only as a whole bundle: taking it means buying exactly factor units at price each, so the bundle costs factor times price and yields factor units. A line may be taken once or left alone.

With budget to spend, return the greatest number of units that can be bought.

Examples

Example 1

Input
items = [[3, 4], [7, 2], [2, 9], [5, 3]], budget = 40
Output
12

The four bundles cost 12, 14, 18 and 15 and yield 3, 7, 2 and 5 units. Taking the second and fourth costs 29 and yields 12 units, and no choice inside 40 does better.

Example 2

Input
items = [[10, 1], [1, 10]], budget = 10
Output
10

One bundle costs 10 and yields 10 units, the other costs 10 and yields 1, so the budget goes on the first.

Example 3

Input
items = [[1, 2]], budget = 1
Output
0

The only bundle costs 2, which is over budget, so nothing can be bought.

Constraints

  • 1 <= items.length <= 1000
  • items[i].length == 2
  • 1 <= items[i][0] <= 1500
  • 1 <= items[i][1] <= 1500
  • 1 <= budget <= 1500

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def maximum_sale_items(items: list[list[int]], budget: int) -> int:
Java
public int maximumSaleItems(int[][] items, int budget)
September 7
Apply