You are given n assets, where each asset has a cost (the amount of capital required to invest) and a projected return value. You also have a total budget representing your available capital.
Select a subset of assets to maximize the total return value without exceeding the budget. Each asset can only be selected at most once.
Return the maximum total return value achievable within the given budget.
Function Signature
def max_portfolio_value(costs: list[int], returns: list[int], budget: int) -> int:
Rules
-
Asset
i
has cost
costs[i]
and return
returns[i]
.
-
A selection is valid when the sum of its costs is at most
budget
. Spending exactly the budget is allowed, and so is leaving part of it unused.
-
Each asset is either taken once or not at all. Fractions of an asset are not allowed.
-
Return only the maximum total return, not the chosen assets.
Constraints
-
1 <= n <= 200
, and
len(costs) == len(returns) == n
-
1 <= budget <= 10000
-
1 <= costs[i] <= budget
-
1 <= returns[i] <= 10000
Examples
Input: costs = [10, 20, 30], returns = [60, 100, 120], budget = 50
Output: 220
Assets 1 and 2 cost 20+30=50 and return 100+120=220. Taking all three would cost 60, and every other pair returns less (160 or 180).
Input: costs = [5, 10, 15, 20], returns = [10, 30, 20, 50], budget = 25
Output: 60
Assets 0 and 3 cost 5+20=25 and return 60. The next best valid choice is assets 1 and 2 (cost 25, return 50). Assets 1 and 3 would return 80 but cost 30, which is over the budget.
Input: costs = [6, 7], returns = [5, 8], budget = 10
Output: 8
Both assets together cost 13, so only one can be taken. Asset 1 returns more, and the 3 units of unused budget are fine.