Exam Seating
Time limit3sMemory limit128 MB
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 grid, numbered from to . At each location sits a student with skill and shoulder width . An unoccupied seat is modeled as and .
Sitting at seat you can only see "forward", meaning you can only copy from seats with . A student at is modeled as the straight segment from to , and you can never see through any student segment. Each student keeps the exam in the middle, at .
Formally, sitting at you can possibly see an exam at if and the straight line from to does not pass through any student other than the one at . 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 and a student sits at (Euclidean) distance , you cannot read anything. At distance you can read a fraction 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 , the number of data sets. It is followed by data sets of the following form.
The first line of a data set contains two numbers: the integer classroom size and your eyesight (a floating-point number).
This is followed by lines; line describes the student at position . Each such line contains two numbers and : the student's skill and shoulder width. Both are non-negative floating-point numbers, and the width is at most . 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 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.