Brought Down the Grading Server?
시간 제한2초메모리 제한1024 MB
각 코어가 받은 제출물 목록을 재배열해, 매 분마다 모든 코어에서 동시에 평가되는 작업별 제출물 수의 최댓값과 최솟값 차이가 1 이하가 되도록 한다.
문제
A hectic first competition day has passed… While the Scientific Committee narrowly fought off the hacking attack on the grading server, they fear that it affected the scoring of the submissions. There is only one option: all submissions have to be rejudged!
The grading server has processor cores. The committee has already assigned a list of submissions to each core, where each submission is to one of the tasks of the competition (numbered ). The committee made sure that is a power of two.* Now, in the next minutes, each core will evaluate exactly one submission from its list per minute.
Unfortunately, the database containing the task data is quite fragile and could crash if the number of simultaneous requests for a single task’s data varies widely. Therefore, the committee wants to order the submissions of each core in such a way that, during the rejudging, the maximum and minimum number of simultaneously evaluated submissions for any single task differ by at most one.
Write a program which computes such an ordered assignment of the submissions to the cores.
* Due to a bug,† the judging system would crash otherwise, taking down all firewalls and potentially exposing sensitive information!
† You had one job, Wolfgang!
입력
The first line of input contains the three integers , , and described above.
Then, lines follow describing the submissions assigned to the cores. The -th of these lines contains integers (), meaning that the -th core is assigned submissions to the tasks respectively.
출력
Your program should output lines that describe an ordered assignment of the submissions to the cores such that the maximum and minimum number of simultaneously evaluated submissions for any single task differ by at most one: The -th of these lines should contain integers , meaning that the -th core evaluates a submission to task during the -th minute. It is guaranteed that such an assignment exists for each testcase.
힌트
In the output of the first example, the difference between the maximum and the minimum number of simultaneously evaluated submissions is one for tasks and and zero for task . On the other hand, ordering the submissions as in the input would not have constituted a valid output because the difference between the maximum and the minimum number of simultaneously evaluations submissions for task is two.
In the output of the second example, the difference between the maximum and the minimum number of simultaneously evaluated submissions is zero for all three tasks.