This page is still under construction.

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

Radar Installation

Interview

Time limit1sMemory limit128 MB

Summary
Each island on the sea side of a line must be covered by radars of reach d placed on the line, so find the minimum number of placements or report -1 if some island is unreachable.
Level

Medium5 of 10

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

Problem

Assume the coastline is an infinitely long straight line. Land lies on one side of the coastline and sea on the other. Each island is a single point located on the sea side. A radar installation placed on the coastline can cover a distance of dd, so an island in the sea is covered by a radar if the distance between them is at most dd.

We use a Cartesian coordinate system in which the coastline is the x-axis. The sea side is above the x-axis (positive yy) and the land side is below it. Given the position of each island in the sea and the coverage distance dd of a radar, write a program to find the minimum number of radar installations needed to cover all islands. Each island's position is given by its x- and y-coordinates.

Figure A. A sample input of radar installations

Input

The input consists of several test cases. The first line of each case contains two integers nn (1≤n≤10001 \le n \le 1000) and dd, where nn is the number of islands in the sea and dd is the coverage distance of a radar. This is followed by nn lines, each containing two integers that give the coordinates of one island. A blank line separates consecutive cases.

The input is terminated by a line containing a pair of zeros (0 0).

Output

For each test case, print one line in the form Case x: y, where x is the test case number (starting from 1) and y is the minimum number of radar installations needed. If not all islands can be covered, print -1 in place of y.

Examples1

  1. Example 1

    Input
    3 2
    1 2
    -3 1
    2 1
    
    1 2
    0 2
    
    0 0
    
    Expected output
    Case 1: 2
    Case 2: 1