Maximum Performance of a Team LeetCode solution in Python

1
class Solution:
2
def maxPerformance(
3
self, n: int, speed: List[int], efficiency: List[int], k: int
4
) -> int:
5
l = list(zip(efficiency, speed))
6
l.sort(reverse=True)
7
h = []
8
res = 0
9
mod = 1000000007
10
mx_sum = 0
11
print(l)
12
for i in range(n):
13
res = max(res, (mx_sum + l[i][1]) * l[i][0])
14
if len(h) < k - 1:
15
heappush(h, l[i][1])
16
mx_sum += l[i][1]
17
elif k != 1:
18
x = 0
19
if h:
20
x = heappop(h)
21
heappush(h, max(x, l[i][1]))
22
mx_sum = mx_sum - x + max(x, l[i][1])
23
return res % mod

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0