Aerobics Mat Placement
Time limit5sMemory limit512 MB
Place disc centers row by row with the given greedy rule along the longer side of the mat and print the coordinates.
- Level
Easy3 of 10
- Topics
- Simulation, Greedy
- Solved
- No attempts yet
Problem
An aerobics class is about to start. The trainer tells the students to spread out on the training mat so that everyone can swing her arms without hitting anybody. The students keep shuffling around without settling down, so the trainer asks you to compute the positions instead.
The mat is a rectangle of width and length . Student needs a disc of radius , the reach of her arms, all to herself. Two discs may touch but may not overlap. Each student stands on the mat, so her center satisfies and . Arms may reach past the edge of the mat.
The mat is roomy: its area is at least five times the total area of the discs. A valid arrangement always exists, and the output section fixes the single arrangement you must print.
Input
The first line contains the number of test cases . Each test case is two lines. The first line contains three integers , and : the number of students, the width of the mat and the length of the mat. The second line contains integers , the reach of the arms of each student.
Limits
Output
For each test case print one line "Case #n: " followed by integers separated by single spaces, where is the position of student and is the case number starting from 1. Print exactly the arrangement that the following construction produces.
Let be the largest reach in the test case. Students are placed in rows, in input order. A row takes students until one no longer fits, and that student opens the next row.
If , the rows are parallel to the axis. Every student in row , counted from , has . The first student of a row has . For any other student, let be the coordinate of the student placed just before her in the same row, that student's reach and her own reach. She takes when this value is at most ; when it is greater than , she opens the next row at instead.
If , apply the same construction with the two axes exchanged: every student in row has , the coordinate chosen inside a row is the coordinate, and the value compared against is .
Every coordinate this construction produces is an integer, and the limits guarantee that all students stay on the mat.