This page is still under construction.

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

Monopoly

Time limit1sMemory limit128 MB

Summary
Given points on a grid, connect two points with an edge when their Manhattan distance is at most c; report the number of connected components and the largest component size.
Level

Medium7 of 10

Topics
Graph, Union-find, Sorting, Geometry
Solved
No attempts yet

Problem

The internet has finally reached Byteland. The first step in bringing the whole country online is to lay some cables in the capital. A company called Byteland Telecom (BT) is ready to take the job, but local regulations and infrastructure limits make it trickier than it first looks.

There are nn buildings in the capital, each sitting at the intersection of a street and an avenue. Streets run North to South and avenues run East to West. Any two adjacent parallel streets are 11 byteyard apart, and likewise for avenues. Streets are numbered with consecutive integers from West to East, and avenues from South to North.

Internet cables may only run along streets and avenues. Connecting a building at coordinates (x1,y1)(x_1, y_1) (the intersection of street x1x_1 and avenue y1y_1) to a building at (x2,y2)(x_2, y_2) needs ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2| byteyards of cable. No single cable may be longer than cc byteyards, and cables may only be joined at buildings.

To prevent a monopoly, each telecom company may install at most one transmitter-receiver, placed on the roof of one building. That transmitter provides internet to everyone in any building connected to it, directly or indirectly, through the cable network.

BT's CEO wants to know two things: how many additional telecom companies are needed so that every building is served by at least one company, and the largest number of buildings BT can link into a single network.

Input

The first line contains two integers nn and cc (1≤n≤100 0001 \le n \le 100\,000, 1≤c≤1091 \le c \le 10^9): the number of buildings and the maximum length of a single cable. Buildings are numbered from 11. Each of the next nn lines contains two integers xix_i and yiy_i (1≤xi,yi≤1091 \le x_i, y_i \le 10^9): the coordinates of the ii-th building.

Output

Print two integers separated by a space: first, the minimum number of telecom companies other than BT that must provide service so that every building is covered; second, the maximum number of buildings BT can serve with a single transmitter while following all the rules.

Examples3

  1. Example 1

    Input
    4 2
    1 1
    3 3
    2 2
    10 10
    
    Expected output
    1 3
    
  2. Example 2

    Input
    1 1000000000
    5 5
    
    Expected output
    0 1
    
  3. Example 3

    Input
    5 1000000000
    1 1
    1000000000 1000000000
    500 500
    1 1000000000
    999999999 2
    
    Expected output
    0 5