Most Profit Assigning Work

There are n jobs and m workers. Job i has difficulty[i] and pays profit[i]; worker j can only do a job whose difficulty is at most worker[j]. Each worker does at most one job, and a job can be done by any number of workers. Return the maximum total profit.

30:00

Most Profit Assigning Work
medium
Free written solution
Topics
Companies

There are n jobs and m workers. Job i has difficulty[i] and pays profit[i]; worker j can only do a job whose difficulty is at most worker[j]. Each worker does at most one job, and a job can be done by any number of workers. Return the maximum total profit.

Example 1:
Input: {"difficulty":[2,4,6,8,10],"profit":[10,20,30,40,50],"worker":[4,5,6,7]}
Output: 100
Constraints:
  • n=difficulty.length=profit.lengthn = \text{difficulty.length} = \text{profit.length}

  • m=worker.lengthm = \text{worker.length}

  • 1≤n,m≤1041 \leq n, m \leq 10^4

  • 1≤difficulty[i],profit[i],worker[i]≤1051 \leq \text{difficulty}[i], \text{profit}[i], \text{worker}[i] \leq 10^5

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"difficulty":[2,4,6,8,10],"profit":[10,20,30,40,50],"worker":[4,5,6,7]}

5 jobs and 4 workers. Each worker should take the best-paying job they are skilled enough for; jobs can be shared.

jobs: x = difficulty, height = profit

gold line = best pay unlocked

0101020304050workers

workers

4

.

5

.

6

.

7

.

best unlocked

0

total

0

Variables
VariableValue
skillnull
i0
best0
total0
DepthFunction Call
Stack empty
0/13