2431. Maximize Total Tastiness of Purchased Fruits
Содержание
class Solution:
def maxTastiness(
self, price: List[int], tastiness: List[int], maxAmount: int, maxCoupons: int
) -> int:
@cache
def dfs(i, j, k):
if i == len(price):
return 0
res = dfs(i + 1, j, k)
if j >= price[i]:
res = max(res, dfs(i + 1, j - price[i], k) + tastiness[i])
if j >= price[i] // 2 and k:
res = max(res, dfs(i + 1, j - price[i] // 2, k - 1) + tastiness[i])
return res
return dfs(0, maxAmount, maxCoupons)