Problem
Suppose LeetCode will start its IPO soon. To sell a good price of its shares, it can only finish at mostk distinct projects before the IPO. Help LeetCode maximize its total capital.
You are given n projects where the ith project has a pure profit profits[i] and a minimum capital capital[i] is needed to start it.
Initially, you have w capital. When you finish a project, you obtain its pure profit, which is added to your total capital.
Pick a list of at most k distinct projects to maximize your final capital, and return the final maximized capital.
Examples
Constraints
- 1 <= k <= 10^5
- 0 <= w <= 10^9
- n == profits.length
- n == capital.length
- 1 <= n <= 10^5
- 0 <= profits[i] <= 10^4
- 0 <= capital[i] <= 10^9