Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.19 KB

_826. Most Profit Assigning Work.md

File metadata and controls

44 lines (31 loc) · 1.19 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 18, 2024

Last updated : June 18, 2024


Related Topics : Array, Two Pointers, Binary Search, Greedy, Sorting

Acceptance Rate : 55.883 %


Solutions

Python

class Solution:
    def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:
        heap = [(-profit[i], difficulty[i]) for i in range(len(difficulty))]
        heapq.heapify(heap)

        worker.sort()

        output = 0
        while worker and heap:
            if worker[-1] >= heap[0][1] :
                output += -heap[0][0]
                worker.pop()
            else :
                heapq.heappop(heap)

        return output