IPO

Problem Id: 502 Difficulty: Hard


Intuition

Solution


class Solution:
    def findMaximizedCapital(self, k: int, W: int, Profits: List[int], Capital: List[int]) -> int:
        pc = sorted(zip(Capital, Profits))
        current = W
        heap = []
        i = 0
        for _ in range(k):
            while i < len(pc) and pc[i][0] <= current:
                heapq.heappush(heap, -pc[i][1])
                i += 1
            if not heap:
                break
            current += -heapq.heappop(heap)
        return current