Aerobics Mat Placement

Time limit5sMemory limit512 MB

Summary
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 WW and length LL. Student ii needs a disc of radius rir_i, 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 0≤x≤W0 \le x \le W and 0≤y≤L0 \le y \le L. 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 TT. Each test case is two lines. The first line contains three integers NN, WW and LL: the number of students, the width of the mat and the length of the mat. The second line contains NN integers r1,r2,…,rNr_1, r_2, \dots, r_N, the reach of the arms of each student.

Limits

  • 1≤T≤501 \le T \le 50
  • 1≤N≤101 \le N \le 10
  • 1≤W,L≤1091 \le W, L \le 10^9
  • 1≤ri≤1051 \le r_i \le 10^5
  • 5π(r12+r22+⋯+rN2)≤W⋅L5\pi(r_1^2 + r_2^2 + \dots + r_N^2) \le W \cdot L

Output

For each test case print one line "Case #n: " followed by 2N2N integers x1 y1 x2 y2 … xN yNx_1\ y_1\ x_2\ y_2\ \dots\ x_N\ y_N separated by single spaces, where (xi,yi)(x_i, y_i) is the position of student ii and nn is the case number starting from 1. Print exactly the arrangement that the following construction produces.

Let RR 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 W≥LW \ge L, the rows are parallel to the xx axis. Every student in row jj, counted from j=0j = 0, has y=2Rjy = 2Rj. The first student of a row has x=0x = 0. For any other student, let pp be the xx coordinate of the student placed just before her in the same row, rpr_p that student's reach and rcr_c her own reach. She takes x=p+rp+rcx = p + r_p + r_c when this value is at most WW; when it is greater than WW, she opens the next row at x=0x = 0 instead.

If W<LW < L, apply the same construction with the two axes exchanged: every student in row jj has x=2Rjx = 2Rj, the coordinate chosen inside a row is the yy coordinate, and the value compared against is LL.

Every coordinate this construction produces is an integer, and the limits guarantee that all students stay on the mat.

Examples1

  1. Example 1

    Input
    2
    2 6 6
    1 1
    3 320 2
    4 3 2
    
    Expected output
    Case #1: 0 0 2 0
    Case #2: 0 0 7 0 12 0