📌📌Python3 || ⚡783 ms, faster than 98.25% of Python3
\n\ndef findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:\n        if w >= max(capital):\n            return w + sum(nl
![image](https://assets.leetcode.com/users/images/73a9e1bd-d8b5-4ad9-902e-e3290dfae2ec_1677156815.4678285.png)\n```\ndef findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:\n        if w >= max(capital):\n            return w + sum(nlargest(k, profits))        \n        projects = [[capital[i],profits[i]] for i in range(len(profits))]\n        projects.sort(key=lambda x: x[0])        \n        heap = []        \n        for i in range(k):\n            while projects and projects[0][0] <= w:\n                heappush(heap, -1*projects.pop(0)[1])            \n            if not heap:\n                break\n            p = -heappop(heap)\n            w += p\n        return w\n```\n\nhere\'s a step-by-step explanation of the code:\n1. The function findMaximizedCapital takes in four arguments: k, w, profits, and capital. k represents the maximum number of projects that can be selected, w represents the initial amount of capital, profits is a list of profits that can be earned from each project, and capital is a list of minimum capital required to start each project.\n1. If the initial amount of capital w is greater than or equal to the maximum value of capital, then we can select all projects and earn maximum profit. So, we return the sum of w and the sum of k largest profits from the profits list using the nlargest function.\n1. If the initial amount of capital w is less than the maximum value of capital, then we create a list of projects, where each project is represented as a list [capital[i], profits[i]]. This allows us to keep track of the required capital and the corresponding profit for each project.\n1. We sort the list of projects based on the minimum capital required to start each project. This allows us to select projects in increasing order of required capital.\n1. We initialize an empty heap, which we will use to keep track of the maximum profits that can be earned from projects that require less than or equal to the available capital.\n1. We loop k times, since we can select at most k projects.\n1. Within the loop, we check the first project in the sorted list of projects. If the minimum capital required for the project is less than or equal to the available capital w, we add the corresponding profit to the heap.\n1. We then pop the maximum profit from the heap and add it to the available capital w. We repeat this process until we have selected k projects or there are no more projects left in the list.\n1. Finally, we return the final amount of capital w after selecting k projects with maximum profit.
['Heap (Priority Queue)', 'Python', 'Python3']