826. Most Profit Assigning Work

Photo by sol on Unsplash

826. Most Profit Assigning Work

class Solution:
    def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:
        N = len(profit)
        data = [[profit[i], difficulty[i]] for i in range(N)]
        data = sorted(data, key = lambda x: (-1 * x[0], x[1]))

        ans = 0
        for w in worker:
            broke = False
            for profit, diff in data:
                if diff <= w:
                    ans += profit
                    break

        return ans