This page is still under construction.

Parts of this page are still being built. What you see may change.

Subway Planning

Time limit1sMemory limit128 MB

Summary
Given points in the plane and a radius d, cover all points using the fewest rays from the origin, where a ray covers a point if some point on the ray is within distance d.
Level

Hard8 of 10

Topics
Geometry, Greedy, Sorting, Intervals
Solved
No attempts yet

Problem

The government of a country is looking into building a subway system in its capital. For practical reasons, each subway line must start at the central station and then run in a straight line at some angle, extending as far as necessary. You have been hired to investigate whether such an approach is feasible.

Given the coordinates of the important places in the city, together with the maximum distance these places may be from a subway station (possibly the central station, which is already built), compute the minimum number of subway lines needed. You may assume that any number of subway stations can be built along a subway line.

The central station is located at coordinates (0,0)(0, 0). Each line is a ray starting at the origin, and a station may be placed at any point along it. An important place is served when the distance between it and some subway station is at most dd.

Figure 1: The figure above corresponds to the first data set in the example input.

Input

The first line of input contains an integer NN, the number of data sets that follow.

Each data set starts with two integers nn and dd (1≤n≤5001 \le n \le 500, 0≤d≤1500 \le d \le 150). nn is the number of important places in the city that must have a subway station nearby, and dd is the maximum distance allowed between an important place and a subway station.

Then follow nn lines, each containing two integers xx and yy (−100≤x,y≤100-100 \le x, y \le 100), the coordinates of an important place. The central station always has coordinates (0,0)(0, 0). All pairs of coordinates within a data set are distinct, and none is (0,0)(0, 0).

Output

For each data set, output a single integer on its own line: the minimum number of subway lines needed so that every important place is at distance at most dd from some subway station.

Examples1

  1. Example 1

    Input
    2
    7 1
    -1 -4
    -3 1
    -3 -1
    2 3
    2 4
    2 -2
    6 -2
    4 0
    0 4
    -12 18
    0 27
    -34 51
    
    Expected output
    4
    2