Dsa
Greedy
Medium
Task Allocation
You are given a list of tasks, each with a duration and a limited number of workers available to complete them. Your goal is to allocate the tasks among the workers to minimize the total time taken to complete all the tasks. Each worker can only work on one task at a time, and they can take multiple tasks, but the total duration of tasks assigned to each worker should not exceed the average duration per worker.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 100), the number of tasks.
- The second line contains n space-separated integers, the durations of the tasks (1 ≤ duration ≤ 100).
- The third line contains an integer m (1 ≤ m ≤ 20), the number of available workers.
Output format:
- Print the minimum total time to finish all tasks.
Example:
Input:
5
2 4 6 8 10
2
Output:
14
Key concepts
greedyschedulingoptimization
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now