

Given N tasks and N people who can work on them. Each task requires A[i] (0 <= i <= N-1) units of work to complete and each person can do at most B[i] units of work per day. Assign a task to each person so that the total time taken to complete all the tasks is minimized. Find the minimum number of days taken to complete all the tasks.
Note: Every person has to do exactly one task and two or more people can’t work on the same task.
Examples:
Input: N = 3, A = {6, 3, 6}, B = {2, 6, 8}
Output: 2
Explanation: Assign 1st task to 2nd person, 2nd task to 1st person and 3rd task to 3rd person.
Days taken by 1st, 2nd and 3rd person will be: 2, 1, 1ÂInput: N = 2, A = {100, 100}, B = {1, 200}
Output: 100
Explanation: Since the work required by both tasks is same, we can assign them in any order.
Â
Approach: To solve the problem follow the below idea:
Assign maximum amount of work to the person who can do maximum units of work per day. This results in the calculation of minimum days required to complete all the tasks.Â
Follow the given steps to solve the problem:
- Sort both the arrays in decreasing order
- Iterate over both the arrays simultaneously to calculate the number of days
- If A[i] is less than or equal to B[i], then only one day is required to complete this task
- Else if A[i] % B[i] is not equal to zero then (A[i] / B[i]) + 1 days will be required
- Otherwise, A[i] / B[i] days will be required.
- The maximum value from the calculated days is the required answer.
Below is the implementation for the above approach:
Python3
|
Time Complexity: O(N * log N)
Auxiliary Space: O(1)