#C9507. Efficient Message Distribution

    ID: 53608 Type: Default 1000ms 256MiB

Efficient Message Distribution

Efficient Message Distribution

You are given N servers and M messages. Each message has an associated processing time. Your task is to assign each message to one of the servers such that the difference between the maximum total processing time and the minimum total processing time among all servers is minimized. The messages arrive sequentially and their processing times are given in order. Use a greedy strategy with a min‐heap to always assign the next message to the server that currently has the least workload.

Note: The message indices are 1-indexed. If there are multiple valid distributions, any one is acceptable as long as all messages are assigned and the servers’ loads are balanced as much as possible.

inputFormat

The input is read from standard input and consists of two lines. The first line contains two integers N and M separated by a space, representing the number of servers and the number of messages respectively. The second line contains M integers separated by spaces, where each integer denotes the processing time of a message.

outputFormat

For each server from 1 to N (in order), print a line containing the 1-indexed message indices that are assigned to that server. The indices should be separated by a single space. If a server does not receive any messages, output an empty line for that server.

## sample
2 6
1 2 3 2 1 3
1 3 5

2 4 6

</p>