Ctrl K

Fruit Basket With Coupons

Medium
A market sells n fruits. Fruit i costs prices[i] coins and is worth flavor[i] flavor points. You have budget coins and coupons coupons. Each fruit can be bought at most once. A coupon can be applied to a purchase, making that fruit cost half its price rounded down (prices[i] // 2). You may use at most coupons coupons in total and at most one per fruit. The total amount you pay must not exceed budget. Return the largest total flavor you can collect.
Example 1
prices=[8, 6, 12], flavor=[4, 7, 9], budget=12, coupons=1 → 16

Buy the 12-coin fruit with the coupon (6) and the 6-coin fruit at full price: exactly 12 coins and 9 + 7 = 16 flavor.

Example 2
prices=[0, 9], flavor=[5, 6], budget=4, coupons=2 → 11

The first fruit is free, and the second costs 9 // 2 = 4 with a coupon. That is 4 coins and 11 flavor.

Example 3
prices=[7, 5], flavor=[3, 8], budget=3, coupons=0 → 0
Constraints
  • 1 ≤ n ≤ 100, len(prices) = len(flavor) = n
  • 0 ≤ prices[i], flavor[i] ≤ 1000
  • 0 ≤ budget ≤ 1000
  • 0 ≤ coupons ≤ 5
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFewest Jumps to the End MediumMost Profitable Streak MediumReach the Last Cell MediumWarehouse Cart Routes MediumCheapest Corner-to-Corner Route Medium
loading Python…
Input
prices=[8, 6, 12], flavor=[4, 7, 9], budget=12, coupons=1
Expected
16

Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.