1037. Maximize Profit from Task Assignment

You are provided with an integer array workers, where workers [i] represents the skill level of the ith worker.

You are also provided with a 2D array tasks, where:

• tasks [i] [0] represents the skill level required to complete the task.

• tasks [i] [1] represents the profit earned after completing the task.

Each worker can complete at most one task, and they may take a task only if their skill level is equal to the task’s required skill. An additional worker joins today who can take up any one task, regardless of the skill requirement.

Return the maximum total profit that can be earned by optimally assigning the tasks to the workers.

Example 1:

Input: workers = [1, 2, 3, 4] , tasks = [ [2, 100] , [2, 400] , [3, 100] , [3, 400] ]

Output: 1000

Explanation:

  • Worker[0[ completes tasks[1].
  • Worker[2] completes tasks[3].
  • The additional worker completes tasks[1].

Example 2:

Input: workers = [100000000] , tasks = [ [100, 100] ]

Output: 100

Explanation:

Since no worker matches the skill requirement, only the additional worker can complete task 0.

Now Your Turn!

Pick the correct output for the given input

Input: workers = [7], tasks = [ [3, 3] , [3, 3] ]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= workers.length <= 105
  • 1 <= workers[i] <= 109
  • 1 <= tasks.length <= 105
  • tasks[i].length == 2
  • 1 <= tasks[i][0], tasks[i][1] <= 109

Hints

Fun Facts

0
class Solution {
public:
long long maxProfit(vector<int>& workers, vector<vector<int>>& tasks) {
// Your code goes here
}
};
Test Case

Input:

Tasks
Workers