Most Profit Assigning Work - Problem
Imagine you're running a freelance job marketplace where you need to assign workers to projects to maximize total profit! ๐ผ
You have n jobs and m workers. Each job has a specific difficulty level and profit amount. Each worker has a certain ability level - they can only complete jobs with difficulty at most equal to their ability.
Key Rules:
- Every worker can be assigned at most one job
- One job can be completed by multiple workers (think of it as identical tasks)
- If a worker can't complete any job, they earn
$0
Goal: Return the maximum total profit you can achieve by optimally assigning workers to jobs.
Example: If you have 3 workers who can all do a job that pays $5, your total profit would be $15!
Input & Output
example_1.py โ Basic Assignment
$
Input:
difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]
โบ
Output:
100
๐ก Note:
Workers with abilities [4,5,6,7] can do jobs with max difficulties [4,4,6,6] earning profits [20,20,30,30]. Total = 20+20+30+30 = 100.
example_2.py โ Some Workers Can't Work
$
Input:
difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25]
โบ
Output:
0
๐ก Note:
All workers have abilities less than the minimum job difficulty (47), so no one can work. Total profit = 0.
example_3.py โ Multiple Workers Same Job
$
Input:
difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,4,4]
โบ
Output:
60
๐ก Note:
All three workers have ability 4, so they can all do the job with difficulty 4 and profit 20. Total = 20+20+20 = 60.
Constraints
- 1 โค difficulty.length โค 104
- 1 โค profit.length โค 104
- difficulty.length == profit.length
- 1 โค worker.length โค 104
- 1 โค difficulty[i], profit[i], worker[i] โค 105
- Each worker can be assigned at most one job
- Each job can be completed by multiple workers
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code