Maximize capital with projects

Write codeMedium25 min

Your task

You want to maximize your capital by completing at most k distinct investment projects, starting with initial capital w. You are given two arrays: profits[i] is the pure profit of project i (added to your capital on completion) and capital[i] is the minimum capital required to start project i. You can only run a project if your current capital is at least its required capital, each project at most once, and profits are non-negative. Return the maximum capital after completing at most k projects. There are 1 to 10^5 projects; k, w, profits, and capital are non-negative and fit in 32-bit signed range.

Examples

maximized_capital(k: int, w: int, profits: list[int], capital: list[int]) -> int
Example 1
Inputmaximized_capital(2, 0, [1, 2, 3], [0, 1, 1])
Output4