#C7776. Task Distribution Problem
Task Distribution Problem
Task Distribution Problem
You are given a list of tasks and a number of team members. Each task is described by its name, priority, and the estimated time required to complete it. Your goal is to assign the tasks to the team members such that the total estimated time for tasks assigned to each member is as balanced as possible.
A greedy strategy is used: tasks are sorted in descending order by their estimated completion time, and then each task is assigned to the team member who currently has the smallest total workload. Formally, if there are (T) tasks and (M) team members, and each task (i) has a time (t_i), then after sorting tasks such that (t_{\sigma(1)} \ge t_{\sigma(2)} \ge \cdots \ge t_{\sigma(T)}), the assignment is done iteratively by assigning the next task to the team member with the minimum accumulated time.
Implement this strategy.
inputFormat
The input is given via standard input. The first line contains two integers (T) and (M) (the number of tasks and team members, respectively). Each of the following (T) lines describes a task with three values: a string (the task name), an integer (the task priority), and an integer (the estimated time to complete the task).
outputFormat
Output (M) lines via standard output. The (i)-th line should contain the task names assigned to the (i)-th team member, separated by a single space. There is no extra space at the end of each line.## sample
4 2
task1 1 3
task2 2 5
task3 1 2
task4 3 4
task2 task3
task4 task1
</p>