Skip to content

Commit

Permalink
Create 16. Maximum Performance of a Team.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirPaulb authored Jan 30, 2023
1 parent eeb1905 commit 3781489
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 15_Greedy/16. Maximum Performance of a Team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://leetcode.com/problems/maximum-performance-of-a-team/
# https://youtu.be/Y7UTvogADH0

class Solution:
def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int:
eng = [(e, s) for e, s in zip(efficiency, speed)]
eng.sort(reverse = True)

minHeap, spd, res = [], 0, 0
for e, s in eng:
if len(minHeap) == k:
spd -= heapq.heappop(minHeap)
spd += s
res = max(res, spd * e)
heapq.heappush(minHeap, s)

return res % 1000000007


# Time: O(N log(N))

0 comments on commit 3781489

Please sign in to comment.