You're managing a freelance agency where workers with specific skill levels need to be matched with tasks that require exact skill matches. Each worker has a skill level, and each task has both a skill requirement and a profit reward.
The Challenge: You have an array workers where workers[i] represents the skill level of the i-th worker, and a 2D array tasks where tasks[i][0] is the skill requirement and tasks[i][1] is the profit for completing that task.
Key Rules:
- Each worker can complete at most one task
- Workers can only take tasks that exactly match their skill level
- A special "super worker" joins who can complete any task regardless of skill requirement
Goal: Return the maximum total profit that can be earned by optimally assigning tasks to workers.
Example: If you have workers with skills [4, 5, 6] and tasks [[4, 10], [5, 15], [6, 20], [7, 25]], the super worker should take the highest profit task (skill 7, profit 25), while regular workers take their matching tasks for a total profit of 10 + 15 + 20 + 25 = 70.
Input & Output
Constraints
- 1 โค workers.length โค 104
- 1 โค tasks.length โค 104
- 1 โค workers[i], tasks[i][0] โค 105
- 1 โค tasks[i][1] โค 105
- Each worker can complete at most one task
- Super worker can take any task regardless of skill requirement