1383. Maximum Performance of a Team (Hard) - TengnanYao/daily_leetcode GitHub Wiki
class Solution(object):
def maxPerformance(self, n, speed, efficiency, k):
"""
:type n: int
:type speed: List[int]
:type efficiency: List[int]
:type k: int
:rtype: int
"""
arr = sorted(zip(efficiency, speed), reverse = True)
result = 0
cur = 0
heap = []
for e, s in arr:
cur += s
heapq.heappush(heap, s)
if len(heap) > k:
cur -= heapq.heappop(heap)
result = max(result, cur * e)
return result % (10 ** 9 + 7)