IPO LeetCode solution in Python
1from heapq import heappush, heappop, nlargest234class Solution:5def findMaximizedCapital(6self, k: int, w: int, profits: List[int], capital: List[int]7) -> int:8if w >= max(capital):9return w + sum(nlargest(k, profits))1011projects = [[capital[i], profits[i]] for i in range(len(profits))]12projects.sort(key=lambda x: x[0])1314heap = []1516for i in range(k):17while projects and projects[0][0] <= w:18heappush(heap, -1 * projects.pop(0)[1])1920if not heap:21break22p = -heappop(heap)23w += p24return w