- Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path0502-ipo.py
35 lines (28 loc) · 873 Bytes
/
0502-ipo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 502. IPO
# https://leetcode.com/problems/ipo
importheapq
classSolution:
deffindMaximizedCapital(self, k: int, w: int, profits: list[int], capital: list[int]) ->int:
n=len(profits)
projects=list(zip(capital, profits))
projects.sort()
q= []
ptr=0
foriinrange(k):
whileptr<nandprojects[ptr][0] <=w:
heapq.heappush(q, -projects[ptr][1])
ptr+=1
ifnotq:
break
w+=-heapq.heappop(q)
returnw
# ********************#
# TEST #
# ********************#
importunittest
classTestStringMethods(unittest.TestCase):
deftest_addBinary(self):
self.assertEqual(Solution.findMaximizedCapital(self, 2, 0, [1, 2, 3], [0, 1, 1]), 4)
self.assertEqual(Solution.findMaximizedCapital(self, 3, 0, [1, 2, 3], [0, 1, 2]), 6)
if__name__=='__main__':
unittest.main()