IPO

Given initial capital, project profits, and project capital requirements, maximize your final capital by selecting at most k projects. Projects become available only when your current capital is large enough, so you need one heap for availability and another for the best profit choice.

Input Format

k = max projects, w = initial capital, profits and capital are project arrays

Output Format

maximum capital after completing at most k projects

Constraints

  • 1 <= k <= 10^5
  • 0 <= w <= 10^9
  • 1 <= profits.length = capital.length <= 10^5
  • 0 <= profits[i], capital[i] <= 10^9

Examples

Example 1:

Input:

k = 2
w = 0
profits = [1,2,3]
capital = [0,1,1]

Output:

4

Explanation:

Take profit 1 first, then profit 3 becomes available; final capital is 4.

Example 2:

Input:

k = 3
w = 0
profits = [1,2,3]
capital = [0,1,2]

Output:

6

Explanation:

Projects can be unlocked one by one as capital increases.

Loading...
IPO - Heap DSA Problem