Exam Seating

Time limit3sMemory limit128 MB

Summary
For each data set, score every empty seat by the total readable skill of visible forward students, where lines can be blocked by segments, and report the maximum.
Level

Hard8 of 10

Topics
Geometry, Brute force, Implementation
Solved
No attempts yet

Problem

Sometimes the choice of exam seat matters at least as much as your preparation. If you wanted to copy from classmates, you would want a seat from which you can see the exams of (1) many students who are (2) doing well in the class. There is a clear tradeoff: you read a nearby exam better, and sometimes your view is completely blocked by other students, so finding the best seat is a real problem.

All seats sit at integer points of a d×dd \times d grid, numbered from (1,1)(1, 1) to (d,d)(d, d). At each location (x,y)(x, y) sits a student with skill sx,y≥0s_{x,y} \ge 0 and shoulder width wx,y∈[0,1/2]w_{x,y} \in [0, 1/2]. An unoccupied seat is modeled as sx,y=0s_{x,y} = 0 and wx,y=0w_{x,y} = 0.

Sitting at seat (x,y)(x, y) you can only see "forward", meaning you can only copy from seats (x′,y′)(x', y') with y′<yy' < y. A student at (x,y)(x, y) is modeled as the straight segment from (x−wx,y, y)(x - w_{x,y},\, y) to (x+wx,y, y)(x + w_{x,y},\, y), and you can never see through any student segment. Each student keeps the exam in the middle, at (x,y)(x, y).

Formally, sitting at (x,y)(x, y) you can possibly see an exam at (x′,y′)(x', y') if y′<yy' < y and the straight line from (x,y)(x, y) to (x′,y′)(x', y') does not pass through any student other than the one at (x′,y′)(x', y'). If the line passes exactly through the edge of a student's segment, it counts as passing through that student.

Your eyesight is limited, so farther exams are harder to read. If your eyesight is EE and a student sits at (Euclidean) distance D>ED > E, you cannot read anything. At distance D≤ED \le E you can read a fraction 1−D/E1 - D/E of that student's exam. Your total benefit is the sum, over all students whose exams you can see, of their skill weighted by the fraction you can read. Finally, you may only sit in an empty seat.

Input

The first line contains an integer K≥1K \ge 1, the number of data sets. It is followed by KK data sets of the following form.

The first line of a data set contains two numbers: the integer classroom size d≤100d \le 100 and your eyesight E>0E > 0 (a floating-point number).

This is followed by d2d^2 lines; line d(y−1)+xd(y - 1) + x describes the student at position (x,y)(x, y). Each such line contains two numbers ss and ww: the student's skill and shoulder width. Both are non-negative floating-point numbers, and the width is at most 1/21/2. Each data set is guaranteed to contain at least one empty seat.

Output

For each data set, first print Data Set x: on a line by itself, where xx is the data set number (starting from 1). Then print the maximum total benefit you can obtain at the best empty seat in the room, rounded to two decimals.

Examples3

  1. Example 1

    Input
    1
    3 2.2
    0 0
    4 0.4
    2.1 0.2
    6.0 0.2
    0.2 0.1
    0.0 0.0
    10.5 0.5
    0.0 0.0
    0.0 0.0
    
    Expected output
    Data Set 1:
    2.57
    
  2. Example 2

    Input
    1
    2 2
    10 0.3
    4 0.1
    0 0
    0 0
    
    Expected output
    Data Set 1:
    6.17
    
  3. Example 3

    Input
    1
    2 5
    0 0
    9 0.2
    7 0.1
    8 0.3
    
    Expected output
    Data Set 1:
    0.00