#P9214. [入门赛 #11] 洛谷评测机模拟器 (Hard Version)
[入门赛 #11] 洛谷评测机模拟器 (Hard Version)
Background
This problem has exactly the same meaning as the Easy Version. The only difference is the Constraints.
Now suppose you are the Luogu judging system. On this day, Luogu is running contests such as the PION self-test, SCP self-test, and ION self-test at the same time. Tens of thousands of submissions are all coming to you!
Problem Description
Now it is known that you have judging nodes with identical performance, numbered . A judging node can process only one judging task at the same time.
At some moment, judging tasks arrive at the same time. We number these tasks as . The required judging times for these tasks are . Each judging task needs exactly one judging node to run, so you will assign these judging tasks to judging nodes one by one in order from to in the following way:
For a judging task with time cost , you need to find the judging node that currently has the minimum cumulative judging time and assign the task to it. If there are multiple judging nodes whose cumulative judging time is the same and minimal, choose the one with the smallest index.
Definition of “cumulative judging time”: Suppose a judging node is assigned tasks . Then the “cumulative judging time” of this judging node is . Obviously, if a judging node has never been assigned any of these tasks, then its “cumulative judging time” is .
Now you need to count which judging tasks are assigned to each of the judging nodes.
Input Format
The input has two lines.
The first line contains two integers , representing the number of judging nodes and the number of judging tasks.
The second line contains integers , representing the required time of these judging tasks in order.
Output Format
Output lines, each containing several integers separated by a single space.
For the -th line, output the task indices accepted by the -th judging node, sorted in increasing order. If the -th judging node is not assigned any task, output a single on that line.
5 10
13 50 90 38 60 64 60 77 6 24
1 6
2 8
3
4 7
5 9 10
12 7
85 99 82 90 14 11 15
1
2
3
4
5
6
7
0
0
0
0
0
Hint
Constraints
For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5