Cell Phone Antenna
InterviewTime limit1sMemory limit128 MB
Place one antenna of range 1000 on the line y=0 so that the total inhabitants of all covered houses is maximized, and report that maximum.
- Level
Medium6 of 10
- Topics
- Geometry, Intervals, Sorting, Brute force
- Solved
- No attempts yet
Problem
A straight highway is modeled as the line . A single antenna is to be built somewhere on this highway. The antenna has a range of meters: it serves every house whose Euclidean distance to the antenna is at most .
Each house is described by its location and its number of inhabitants . Choose the position of the antenna on the highway so that the total number of inhabitants living in houses within range is as large as possible.
Report that maximum number of inhabitants.
Input
The first line contains the number of test cases . Each test case has the following format:
- A line with an integer with : the number of houses.
- lines follow, each containing three integers , , with and : the location of a house and its number of inhabitants .
The highway is the line .
Output
For each test case, print a single line containing one integer: the greatest number of inhabitants living in houses within range of the antenna (at Euclidean distance at most ), when the antenna is placed at the best possible position along the highway.