#K49222. Minimum Total Task Completion Time
Minimum Total Task Completion Time
Minimum Total Task Completion Time
You are given T test cases. For each test case, you are provided with an integer S representing the number of parallel task slots and an integer N representing the number of tasks. Then, a line with N positive integers follows, each denoting the execution time of a task.
Tasks must be scheduled in the order they are given. At any moment, at most S tasks can be executed concurrently. When a slot becomes free, schedule the next task immediately. Your goal is to compute the minimum total time required to complete all the tasks in each test case.
The scheduling can be simulated using a min‐heap. Essentially, when a task is scheduled, if fewer than S tasks are running, simply start it. Otherwise, assign the task to the slot which becomes available the earliest. Mathematically, if the finish times of tasks in the slots are represented as a set \(\{f_1, f_2, \dots, f_S\}\), the final answer for a test case is:
[ \text{Total Time} = \max{f_1, f_2, \dots, f_S} ]
Read the input from standard input and output the result for each test case on a separate line.
inputFormat
The first line contains an integer T indicating the number of test cases. For each test case:
- A line with two integers: S (the number of parallel slots) and N (the number of tasks).
- A line with N integers, where each integer indicates the execution time of a task.
All inputs are read from standard input (stdin).
outputFormat
For each test case, output a single integer on a separate line representing the minimum total time required to complete all tasks.
All outputs should be written to standard output (stdout).
## sample1
1 1
1
1
</p>