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
Asked in
25.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen