#C9335. Optimal Energy Wave Impact
Optimal Energy Wave Impact
Optimal Energy Wave Impact
You are given N points in a 2D plane, representing the positions of trolls. You are also given a radius R. An energy wave is fired at some optimal point such that all trolls within a disk of radius R from that point are affected. Your task is to determine the maximum number of trolls that can be affected by positioning the energy wave optimally.
The distance between two points \( (x_1, y_1) \) and \( (x_2, y_2) \) is defined by the formula:
[ \text{distance} = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2} ]
You may assume that choosing either one of the troll positions or the midpoint of the line segment joining any two trolls can serve as a candidate position to locate the center of the energy wave.
inputFormat
The first line contains two integers: N
(the number of trolls) and R
(the effective radius of the energy wave). Each of the next N
lines contains two space-separated numbers representing the x
and y
coordinates of a troll.
You can assume that all the input values are valid and properly formatted.
outputFormat
Output a single integer representing the maximum number of trolls that can be affected by the energy wave.
## sample5 2
1 1
2 2
3 3
4 4
5 5
3