#K1321. Minimize Maximum Processing Time
Minimize Maximum Processing Time
Minimize Maximum Processing Time
You are given m servers and n tasks. Each task i has a processing time t_i. The goal is to assign all tasks to the servers such that the maximum processing time among all servers is minimized.
The tasks can be assigned in any order. A greedy strategy combined with binary search can be used to decide the minimum possible maximum processing time allowed so that the tasks can be distributed among the servers.
The answer should be computed with the following idea:
- Sort the tasks in non-increasing order.
- Use binary search on the possible maximum processing times from \(\max(t_i)\) to \(\sum t_i\).
- Check if a candidate maximum processing time \(X\) is feasible by simulating the distribution of tasks among the servers.
Formally, if \(T = [t_1, t_2, \dots, t_n]\), find the smallest value \(X\) such that \(\) the tasks can be partitioned into at most \(m\) groups where the sum of each group is \(\le X\).
The key observation is that if a candidate value \(X\) is feasible, then any \(Y > X\) is also feasible. This allows the use of binary search.
inputFormat
The first line of input contains two integers m
and n
, where m
is the number of servers and n
is the number of tasks.
The second line contains n
space-separated integers representing the processing time for each task.
outputFormat
Output the minimized maximum processing time any server takes to complete its assigned tasks.
## sample2 5
1 2 3 4 5
9
</p>