aboutsummaryrefslogtreecommitdiffstats
path: root/502
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2023-02-23 13:08:35 +0000
committerterminaldweller <thabogre@gmail.com>2023-02-23 13:08:35 +0000
commit0c9a53591555fed9a3b4dd9b457e273c8838c9a8 (patch)
tree473b91e2fee03f4b7f59f23bd4300a8b3a105871 /502
parent1011 (diff)
downloadleetcode-0c9a53591555fed9a3b4dd9b457e273c8838c9a8.tar.gz
leetcode-0c9a53591555fed9a3b4dd9b457e273c8838c9a8.zip
502
Diffstat (limited to '502')
-rwxr-xr-x502/main.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/502/main.py b/502/main.py
new file mode 100755
index 0000000..08dcbaa
--- /dev/null
+++ b/502/main.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+from typing import List
+import heapq
+
+
+class Solution:
+ def findMaximizedCapital(
+ self, k: int, w: int, profits: List[int], capital: List[int]
+ ) -> int:
+ n = len(profits)
+ projects = list(zip(capital, profits))
+ print(projects)
+ projects.sort()
+ print(projects)
+
+ q = []
+ ptr = 0
+
+ for _ in range(k):
+ while ptr < n and projects[ptr][0] <= w:
+ heapq.heappush(q, -projects[ptr][1])
+ ptr += 1
+ if not q:
+ break
+ w += -heapq.heappop(q)
+
+ return w
+
+
+if __name__ == "__main__":
+ solution = Solution()
+ print(solution.findMaximizedCapital(2, 0, [1, 2, 3], [0, 1, 1]))