IPO
HardHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.A small company wants to grow its capital before going public. It starts with capital w and can finish at most k distinct projects. Project i can only be started when the current capital is at least capital[i], and finishing it adds profits[i] to the capital (the starting capital is not spent).
Pick projects one at a time to maximize the final capital, and return it.
k = 2, w = 0, profits = [1, 2, 3], capital = [0, 1, 1] → 4With 0 capital only project 0 is open: do it and reach 1. Now projects 1 and 2 are open: pick project 2 (profit 3) and finish with 4.
Constraints
1 <= k <= 10^50 <= w <= 10^91 <= n <= 10^5(n is the number of projects)0 <= profits[i] <= 10^40 <= capital[i] <= 10^9