2024-06-15 10:32:54 +0000 UTC
IPO
Categories:
Links
Code
class Solution:
def findMaximizedCapital(
self, k: int, w: int, profits: List[int], capital: List[int]
) -> int:
n = len(profits)
projects = [(capital[i], profits[i]) for i in range(n)]
projects.sort()
maxHeap = []
i = 0
for _ in range(k):
while i < n and projects[i][0] <= w:
heapq.heappush(maxHeap, -projects[i][1])
i += 1
if not maxHeap:
break
w -= heapq.heappop(maxHeap)
return w