Aerobics (Large)
Time limit5sMemory limit512 MB
Sort students by reach, largest first, then place them line by line on the mat following the prescribed packing rule.
- Level
Easy3 of 10
- Topics
- Simulation, Sorting
- Solved
- No attempts yet
Problem
The aerobics class begins. The trainer asks the students to stand on the mat so that everybody can swing her arms freely without hitting anybody else. The students keep milling around, so the trainer asked for a program that assigns the positions instead.
The mat is a rectangle of width and length . Student needs a circle of radius around the point where she stands, where is the reach of her arms. Two circles may touch but may not overlap, so the distance between the centers of student and student has to be at least . Every center has to lie on the mat, that is and . The arms may reach outside the mat.
The mat is roomy. Its area is at least five times the total area of the circles, so holds and a valid placement always exists.
Many placements are valid, so this problem accepts only the one placement produced by the rule given in the output section.
Input
The first line contains the number of test cases . Each test case consists of two lines. The first line contains the number of students , the width of the mat, and the length of the mat, separated by spaces. The second line contains integers , where is the reach of the arms of student .
The constraints are the following.
- The sum of over all test cases is at most 6000.
Output
For each test case print one line that starts with Case #n: and continues with integers separated by single spaces. Here is the number of the test case, counting from 1, and the integers are , , , and so on in the input order, where is the point at which student stands.
The placement is fixed by the following rule.
First sort the students by reach, largest first. Students with the same reach keep their input order. Call the result the placement order.
If , the students are grouped into vertical lines. The students of one line share the same and get increasing . In that case the length of a line is bounded by , the coordinate that moves inside a line is , and the coordinate that moves from line to line is . If , the two axes are exchanged and the lines are horizontal. The students of one line share the same and get increasing , with , and .
Take the students one at a time in placement order and add each to the current line.
- The first line has .
- The first student of a line stands at .
- Any other student is placed relative to the student placed just before her. If has reach at coordinate and , then student joins the same line at .
- Otherwise student opens a new line. If is the reach of the first student of the line being closed, the new line has equal to the of the closed line plus , and student stands at of that new line.
Every coordinate this rule produces is an integer, and under the constraints of the problem every coordinate stays on the mat.