🚀Simplest Solution🚀 Beginner Friendly||🔥Priority Queue||🔥C++|| Python3🔥
Consider\uD83D\uDC4D\n\n                    Please Upvote If You Find It Helpful\n\n\n# Intuition\nExplanation\nThis code will first create a vector of pairs co
# Consider\uD83D\uDC4D\n```\n                    Please Upvote If You Find It Helpful\n```\n\n# Intuition\nExplanation\nThis code will first create a vector of pairs containing the capital and profits of each project. It will then sort this vector based on the capital required for each project. Then, it will use a priority queue to store the profits of the projects that can be completed with the available capital.\n\nThe code will then iterate k times and in each iteration, it will check for any projects that can be completed with the current capital and add their profits to the priority queue. It will then pop the top element from the priority queue (which will be the project with the highest profit) and add its profit to the current capital.\n\nFinally, the function will return the final capital after completing k projects.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach : Using Priority Queue\n    Example\n    k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]\n    \nExplanation: \nSince your initial capital is 0, you can only start the project indexed 0.\nAfter finishing it you will obtain profit 1 and your capital becomes 1.\nWith capital 1, you can either start the project indexed 1 or the project indexed 2.\nSo, we push both projext indexed 1 and the project indexed 2 into priority queue.\nSince you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital as it is at the **Top** of priority queue.\nTherefore, output the final maximized capital, which is 0 + 1 + 3 = 4.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: **O(n log n + k log n)**, where n is the number of projects. This is because the algorithm sorts the vector of pairs in O(n log n) time, and performs up to k iterations of a loop that may involve up to n operations (adding a potential profit to the max heap) and one pop operation on the max heap, which takes O(log n) time.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n ^ 2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\nclass Solution\n{\npublic:\n    int findMaximizedCapital(int k, int w, vector<int> &profits, vector<int> &capital)\n    {\n        int n = profits.size();\n        vector<pair<int, int>> projects;\n        for (int i = 0; i < n; i++)\n            projects.push_back({capital[i], profits[i]});\n\n        sort(projects.begin(), projects.end());\n        priority_queue<int> pq;\n        int i = 0, j = 0;\n        while (k--)\n        {\n            while (i < n && projects[i].first <= w)\n            {\n                pq.push(projects[i++].second);\n            }\n            if (pq.empty())\n                break;\n            w += pq.top();\n            pq.pop();\n        }\n        return w;\n    }\n};\n```\n```python []\nimport heapq\n\nclass Solution:\n    def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:\n        n = len(profits)\n        projects = [(capital[i], profits[i]) for i in range(n)]\n        projects.sort()\n        pq = []\n        i = 0\n        for _ in range(k):\n            while i < n and projects[i][0] <= w:\n                heapq.heappush(pq, -projects[i][1])\n                i += 1\n            if not pq:\n                break\n            w -= heapq.heappop(pq)\n        return w\n```\n\n\n```\n                            Give a \uD83D\uDC4D. It motivates me alot\n```\nLet\'s Connect On [Linkedin](https://www.linkedin.com/in/naman-agarwal-0551aa1aa/)
['Sorting', 'Heap (Priority Queue)', 'Python', 'C++', 'Python3']