#P9610. Maximizing Barbecue Smoke Coverage
Maximizing Barbecue Smoke Coverage
Maximizing Barbecue Smoke Coverage
Ian, the owner of Deep800080, is planning a barbecue on his narrow pier that stretches from the shore into the lake. His special barbecue charcoal produces a unique, deep purple smoke that forms a perfect circle with a fixed maximum radius \(r\) around the grill.
There are several ships anchored at various positions in the lake. A ship is considered alerted if it is within or on the boundary of the smoke circle.
Given the positions of the ships in the plane and the smoke radius \(r\), determine the maximum number of ships that can be alerted by optimally placing the barbecue grill on the pier. You may assume that the pier corresponds to the non\(-negative\) x\(-axis\) (i.e., points of the form \((x,0)\) with \(x \ge 0\)). Each ship is represented by its coordinates \((x_i,y_i)\) in the plane.
Mathematically, for a ship at \((x_i, y_i)\) and a barbecue location \((x,0)\), the ship is alerted if \[ (x_i - x)^2 + y_i^2 \le r^2. \]
Your task is to choose a position \(x \ge 0\) on the x-axis such that the number of ships satisfying the above inequality is maximized, and output that maximum count.
inputFormat
The first line contains two integers \(n\) and \(r\) (\(1 \leq n \leq 10^5\), \(1 \leq r \leq 10^9\)), representing the number of ships and the radius of the smoke circle.
Each of the next \(n\) lines contains two integers \(x_i\) and \(y_i\) (\(|x_i|,|y_i| \leq 10^9\)), representing the coordinates of a ship. It is guaranteed that the ships are located on the lake. Note that the barbecue grill can only be placed on the pier, which is along the non-negative x-axis (i.e. points \((x,0)\) for \(x \ge 0\)).
outputFormat
Output a single integer: the maximum number of ships that can be alerted by optimally placing the barbecue grill.
sample
3 5
2 3
4 2
7 5
2