Problem · Array
Problem statement
You are given n projects. Project i produces a pure profit of profits[i] and requires at least capital[i] current capital before it can be started.
You begin with capital w. After completing a project, immediately add its profit to your capital. Each project may be completed at most once.
Choose at most k distinct projects to maximize your final capital. Return that maximum final capital.
Function
findMaximizedCapital(k: int, w: int, profits: int[], capital: int[]) → intExamples
Example 1
k = 2w = 0profits = [1,2,3]capital = [0,1,1]return = 4Start project 0 to grow the capital from 0 to 1. Projects 1 and 2 then become affordable; choosing project 2 produces final capital 4.
Example 2
k = 3w = 0profits = [1,2,3]capital = [1,1,2]return = 0No project is affordable with initial capital 0, so no project can be completed and the final capital remains 0.
Constraints
1 <= profits.length = capital.length <= 10^51 <= k <= profits.length0 <= w <= 10^90 <= profits[i] <= 10^90 <= capital[i] <= 10^9- The maximum final capital fits in a signed
32-bit integer.