#P3737. Alien Laser Detection

    ID: 16988 Type: Default 1000ms 256MiB

Alien Laser Detection

Alien Laser Detection

The planet ZDM-99 exhibits mysterious laser points which could be the sign of intelligent alien life. In order to detect these laser points, radio telescopes are to be installed along the X-axis. Each telescope can detect signals within a circular range of radius \(R\) centered at its installation point on the X-axis. You are given \(n\) laser points on the planet, with coordinates \(P_i(x_i, y_i)\) (ignore the \(z\)-coordinate). A point \(P_i(x_i, y_i)\) is detectable by a telescope placed at \((x, 0)\) if the Euclidean distance satisfies:

\(\sqrt{(x_i - x)^2 + y_i^2} \le R\)

If \(|y_i| > R\), the laser point \(P_i\) cannot be detected by any telescope since its vertical offset exceeds the detection range.

For each laser point with \(|y_i| \le R\), one can derive an interval on the X-axis in which a telescope can be placed so that the point is detected. Specifically, for a point \(P_i(x_i, y_i)\), let \(d = \sqrt{R^2 - y_i^2}\); then the telescope must be placed in the interval \([x_i - d,\, x_i + d]\).

Your task is to determine the minimum number of telescopes that need to be installed on the X-axis so that all laser points are detected. If any laser point is undetectable, output -1.

inputFormat

The first line contains two integers \(n\) and \(R\), where \(n\) is the number of laser points and \(R\) is the detection radius.

Each of the following \(n\) lines contains two numbers \(x_i\) and \(y_i\) indicating the coordinates of a laser point.

outputFormat

Output a single integer representing the minimum number of telescopes required to cover all laser points. If any laser point cannot be covered, output -1.

sample

3 2
1 2
-3 1
2 1
2