1383. Maximum Performance of a Team
https://leetcode.com/problems/maximum-performance-of-a-team/
Python
from heapq import heappush, heappop
class Solution:
def maxPerformance(self, n: int, speeds: List[int], efficiencies: List[int], k: int) -> int:
mapper = [pair for pair in zip(efficiencies, speeds)]
mapper.sort(reverse=True)
result, speed = 0, 0
heap = []
for eff, spd in mapper:
if len(heap) == k:
speed -= heappop(heap)
speed += spd
heappush(heap, spd)
result = max(result, eff*speed)
return result % (10**9+7)