Easy and Right approach with details
Intuition\nYou are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.\n\nInitially, 
# Intuition\nYou are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.\n\nInitially, you have w capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital.\n\nPick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n-> you can use a greedy approach with the help of a max-heap (priority queue) to efficiently maximize the capital. Here\'s the step-by-step plan:\n\n1): Sort Projects by Capital: First, sort the projects based on their required capital in ascending order.\n2): Use a Max-Heap: Use a max-heap to keep track of the most profitable projects that can be completed with the current available capital.\n3): Iterate Over Projects: Iterate over the projects, and for each project that can be completed with the current capital, add its profit to the max-heap.\n4): Select k Projects: Pick the k most profitable projects by repeatedly extracting the maximum profit from the heap and adding it to the current capital.\n\n![Screenshot 2024-06-15 121443.png](https://assets.leetcode.com/users/images/9375b691-3f5e-412e-8bdf-7963bd1f10c8_1718434244.398345.png)\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- **Time complexity**: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)     +     O(nlogn)      +     O(klogn)    =    O(nlogn+klogn)\n\nSorting the Projects  +  Iterating Over Projects  +  Extracting from the Heap \n\n\n- **Space complexity**: \n*Storing Projects*:  We use an additional list to store the sorted projects, which requires:  O(n) space\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![0cc080cf-616a-4180-b9e6-f46c49f183a8_1718170157.6093411.jpeg](https://assets.leetcode.com/users/images/554b42e4-96e9-402d-baa0-133a5c28d6bb_1718434272.9134476.jpeg)\n\n# Code\n```\nfrom heapq import heappush, heappop\nfrom typing import List\n\nclass Solution:\n    def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:\n        # Create a list of projects where each project is (capital, profit)\n        projects = list(zip(capital, profits))\n        \n        # Sort projects by the required capital\n        projects.sort()\n        \n        max_heap = []\n        current_capital = w\n        i = 0\n        n = len(projects)\n        \n        for _ in range(k):\n            # Push all projects that can be started with the current capital to the max-heap\n            while i < n and projects[i][0] <= current_capital:\n                heappush(max_heap, -projects[i][1])  # Use negative profit to simulate max-heap\n                i += 1\n            \n            # If there are no projects that can be done, break\n            if not max_heap:\n                break\n            \n            # Choose the project with the maximum profit\n            current_capital += -heappop(max_heap)\n        \n        return current_capital\n\n```
['Sorting', 'Heap (Priority Queue)', 'Iterator', 'Python3']