Java + Intuition + 2 Heaps + Greedy + Explanation
Intuition:\n\nThe intuition is to find the max profit for the available capital at any point of time. We add to the total profit, every time we are able to sele
**Intuition:**\n\nThe intuition is to find the **max profit for the available capital** at any point of time. We add to the total profit, every time we are able to select & complete a project with maximum profit. Since our total profit is updated after each project completion, and if we haven\'t completed `k` projects yet, we\'ll try to pick the next project which has the highest profit within the range of newly calculated total profit (till now).\n\n**Algorithm:**\n- We can maintain a `minHeap` of `projects` (pair of `capital` & `profit`), sorted based in ascending order on `capital`.\n- We also maintain a cummulative `sum` of profits, which is updated whenever the maximum profit project is selected with the current available `capital` (`sum` of profits).\n- In order to select the max profit with the current available capital (i.e. the `sum` of profits), we maintain a `maxHeap` of profits which gets populated everytime with the profits of the `projects` which has the cummulative `capital` to execute it.\n- We poll all projects out of the `minHeap` which can be completed with the current capital and add its profits to the `maxHeap`. There might be a point where all elements are polled out of the `minHeap`, but we haven\'t executed `k` projects yet, so in that case the top most element in the `maxHeap` will be the project that can be executed for each iteration.\n- **So at given point of time in the `maxHeap` we will always have the max profit that is possible with the available `capital`.**\n- So we poll the highest profit out of the `maxHeap` and add it to the total profit (cummulative `sum`). The profits which was not selected from the `maxHeap` in this iteration maybe be picked up in the subsequent iteration, until the total number of projects executed is `k`.\n\nAfter each project the cummulative capital grows with the profit earned from the project, and hence we repeat the previous step to check if we can pick up any higher profit project from the `minHeap` which meets the updated capital. If there are no elements left in the `minHeap`, then we simply pick the next max profit from the `maxHeap`. We repeat this process until `k` projects are completed.\n\n\n**Code:**\n\n```\nclass Solution {\n    public int findMaximizedCapital(int k, int W, int[] Profits, int[] Capital) {\n        \n        PriorityQueue<int[]> minCapitalProjects = new PriorityQueue<>((a,b) -> a[0] - b[0]);\n        PriorityQueue<Integer> maxProfits = new PriorityQueue<>((a,b) -> b - a);\n        \n\t\t// Building the minHeap pair of capital and profits, sorted in ascending order of capital        \n        for(int i=0; i<Capital.length; i++)\n            minCapitalProjects.add(new int[]{Capital[i], Profits[i]});\n        \n        // Check until k projects are completed\n        for (int i=0; i < k; i++){\n            // Pick up all projects that meets current cummulative capital and store it in a maxHeap of profits\n            while(!minCapitalProjects.isEmpty() && minCapitalProjects.peek()[0] <= W)\n                maxProfits.add(minCapitalProjects.poll()[1]);\n            if(maxProfits.isEmpty()) \n                return W;\n            // Update the capital by polling the highest profit element from the maxHeap of profits\n            W += maxProfits.poll();\n        }\n        return W;\n    }\n}\n```
['Greedy', 'Java']