파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 9. 11. 23:45

 

class Solution:
    def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int:
        cur_sum, h = 0, []
        ans = -float('inf')
        
        for i, j in sorted(zip(efficiency, speed), reverse=True):
            while len(h) > k-1:
                cur_sum -= heappop(h)
            heappush(h, j)
            cur_sum += j
            ans = max(ans, cur_sum * i)
        
        return ans % (10**9+7)

https://leetcode.com/problems/maximum-performance-of-a-team/

 

Maximum Performance of a Team - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

힙을 활용해서 푸는 문제.

 

반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.09.13
Today's Challenge  (0) 2022.09.12
Today's Challenge  (0) 2022.09.10
Today's Challenge  (0) 2022.09.09
Today's Challenge  (0) 2022.09.08
Comments