IOI Kyrgyzstan Qualification Round 2019 Question 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

IOI Kyrgyzstan Qualification Round 2019

Bishkek, April 2019

Task C. City of Future


Time limit: 2 seconds
Memory limit: 256MB

City council is asking for your help to make City the future technological center of the world. In order
to achive this goal you need to build some bridges between the buildings of City. The buildings are
represented as points with integer coordinates in a two-dimensional plane. A bridge between buildings A
and B can be built if and only if the Manhattan distance between these buildings does not exceed the
given C. That is |XA − XB | + |YA − YB | ≤ C.
City wants to connect as many buildings as possible. In other words, City wants to minimize the number
of connected components in the graph spawned by buildings and bridges. You are to find the minimum
possible number of connected building components and the number of the buildings in the largest one.

Input
The first line contains two numbers N (2 ≤ N ≤ 105 ) and C (1 ≤ C ≤ 109 ), where N is the number of
buildings and C is the upper limit for the Manhattan distances between buildings to build a bridge. The
next N lines contain the building coordinates Xi and Yi (1 ≤ Xi , Yi ≤ 109 ), for i = 1 . . . N . All pairs are
different.

Output
Two natural numbers: the minimum achievable number of connected components in City and the size of
the largest possible component.

Grading
Solutions that work for N ≤ 5000 will receive 28 points.

Examples
Input Output
4 2 2 3
1 1
3 3
2 2
10 10
4 1 4 1
1 1
3 3
2 2
10 10

Page 1 of 1

You might also like