Sort+PQ
502.IPO (M+)
class Solution:
def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int:
modNum = 10 ** 9 + 7
effiSpee = sorted(zip(efficiency, speed))
minHeap = []
heapSum = 0
result = 0
for i in reversed(range(n)):
thisEffi, thisSpee = effiSpee[i]
heapq.heappush(minHeap, (thisSpee, thisEffi))
heapSum += thisSpee
if len(minHeap) > k:
topSpeed, topEffi = heapq.heappop(minHeap)
heapSum -= topSpeed
result = max(result, heapSum * thisEffi)
return result % modNumLast updated