[Python] Priority Queue with Explanation
Explanation\nLoop k times:\nAdd all possible projects (Capital <= W) into the priority queue with the priority = -Profit.\nGet the project with the smallest pri
## Explanation\nLoop `k` times:\nAdd all possible projects (`Capital <= W`) into the priority queue with the `priority = -Profit`.\nGet the project with the smallest priority (biggest Profit).\nAdd the Profit to `W`\n<br>\n\n@tife1379: This visualisation should help understand.\n\n![image](https://i.ibb.co/PQrFr6R/Artboard-1.jpg)\n\nThe reason for sorting and the nature of the iterator is\nto establish Capital Boundaries for projects that\ncan be taken on given your current working capital.\n\nThen after each increment in Pure Profit you "may" be able\nto jump across boundaries to take on more expensive projects,\nwhich may not necessarily be more rewarding than past cheaper projects seen,\nwhich is why the heap is persistent across each boundary traversal.\n<br>\n\n**Python**\n```py\ndef findMaximizedCapital(self, k, W, Profits, Capital):\n        heap = []\n        projects = sorted(zip(Profits, Capital), key=lambda l: l[1])\n        i = 0\n        for _ in range(k):\n            while i < len(projects) and projects[i][1] <= W:\n                heapq.heappush(heap, -projects[i][0])\n                i += 1\n            if heap: W -= heapq.heappop(heap)\n        return W\n````
[]