Python Greedy
The heuristic is, for each investment, we choose the largest profit from current doable projects, where doable means project\'s requested capital is no higher t
The heuristic is, for each investment, we choose the largest profit from current doable projects, where doable means project\'s requested capital is no higher than current ```W```. \nAnd our ```W``` should keep increasing as capital doesn\'t decrease when we invest. Therefore, a greedy search can solve the problem by one-pass scan for each project with order of project\'s capital.\nTo implement it, we first sort project pair (profit, capital) by capital. \nThen for each investment, we push all doable projects (project\'s capital < W) into a max heap ordered by project\'s profit. Then we just pop the project with the highest project and add its profit to our capital ```W```. \nWe do it for ```k``` times and the maximum capital will be stored in ```W```.\n```\ndef findMaximizedCapital(k, W, Profit, Capital):\n\theap, projects = [], sorted(zip(Profit, Capital), key=lambda x:x[1])\n\ti, n = 0, len(projects)\n\tfor _ in range(k):\n\t\twhile i < n and projects[i][1] <= W:\n\t\t\theapq.heappush(heap, (-projects[i][0]))\n\t\t\ti += 1\n\t\tif heap: W -= heapq.heappop(heap)\n\t\telse: break\n\treturn W\n```
[]