Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Shopping Offers

XPChallenge Points: 20
levelLevel: Medium

You want to purchase a set of items, where each item has a fixed cost.
Some bundle offers are also available, where each bundle contains certain quantities of items at a discounted total price.

You are given:

  • price[i] → cost of a single unit of item i

  • needs[i] → how many units of item i you must buy

  • special[j] → a bundle offer (first n values = quantities, last value = offer price)

You may use any offer any number of times, as long as you never buy more items than needed.

Your task is to compute the minimum total amount you must pay to exactly obtain the required items.

Example 1:

Input: price = [3,4] special = [[1,1,6], [2,0,4]] needs = [2,1]

Output: 8

Explanation:

Offer1: 1A + 1B → cost 6 Offer2: 2A → cost 4 To buy 2A and 1B: Use Offer1 once (1A,1B → 6) Buy 1A normally (3) Total = 6 + 3 = 8

Example 2:

Input: price = [5,2,6] special = [[1,1,1,10]] needs = [1,2,1]

Output: 15

Explanation:

Use bundle once → 1A + 1B + 1C for 10 Still need 1 extra B → cost 2 Total = 10 + 2 + 3 = 15

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result