Maximize Total Tastiness of Purchased Fruits - Problem
Imagine you're at a premium fruit market where each fruit has a specific price and tastiness rating. You have a limited budget (maxAmount) and want to maximize the total tastiness of fruits you purchase.
Here's the twist: you have discount coupons (maxCoupons) that let you buy certain fruits at half price (rounded down)! Your goal is to strategically use these coupons to get the maximum possible tastiness within your budget.
Input:
price[]- Price of each fruittastiness[]- Tastiness rating of each fruitmaxAmount- Your total budgetmaxCoupons- Number of discount coupons available
Output: Maximum total tastiness you can achieve
Rules:
- Each fruit can be purchased at most once
- Each coupon can be used at most once
- Coupons reduce price to
price[i] // 2
Input & Output
example_1.py — Basic Example
$
Input:
price = [3, 1, 2], tastiness = [4, 2, 3], maxAmount = 6, maxCoupons = 2
›
Output:
9
💡 Note:
We can buy all three fruits using coupons on the expensive ones: fruit 0 with coupon (price 1, taste 4), fruit 1 at full price (price 1, taste 2), and fruit 2 with coupon (price 1, taste 3). Total cost: 1+1+1=3 ≤ 6, total taste: 4+2+3=9
example_2.py — Limited Budget
$
Input:
price = [5, 3, 1, 6], tastiness = [8, 4, 2, 5], maxAmount = 4, maxCoupons = 1
›
Output:
6
💡 Note:
Best strategy: buy fruit 2 at full price (cost 1, taste 2) and fruit 1 with coupon (cost 1, taste 4). Total cost: 1+1=2 ≤ 4, total taste: 2+4=6. We can't afford fruit 0 or 3 even with coupons.
example_3.py — No Coupons
$
Input:
price = [2, 4, 1], tastiness = [3, 6, 1], maxAmount = 5, maxCoupons = 0
›
Output:
7
💡 Note:
Without coupons, we can buy fruit 1 (price 4, taste 6) and fruit 2 (price 1, taste 1). Total cost: 4+1=5 ≤ 5, total taste: 6+1=7.
Constraints
- 1 ≤ price.length, tastiness.length ≤ 1000
- price.length == tastiness.length
- 0 ≤ price[i], tastiness[i] ≤ 104
- 0 ≤ maxAmount ≤ 104
- 0 ≤ maxCoupons ≤ 1000
- Each fruit can be purchased at most once
- Each coupon can be used at most once
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code