#P51453. [JOISC 2021 Day2] Road Construction

[JOISC 2021 Day2] Road Construction

Description

Original problem from JOISC 2021 Day2 T2 Road Construction.

There are N towns in JOI Kingdom. The towns are numbered from 11 to NN. The land of JOI Kingdom is considered as the xyxy-plane. The coordinates of the town ii (1iN)(1 \leq i \leq N) is (Xi,Yi)(X_i, Y_i).

In JOI Kingdom, they are planning to construct K roads connecting towns. It costs XiXj+YiYj|X_i − X_j| + |Y_i − Y_j| yen to construct a road connecting the town ii and the town j (ij)j~(i \neq j). Note that we consider “the construction of a road connecting the town ii and the town jj” and “the construction of a road connecting the town jj and the town ii” to be the same.

Since you are in charge of the construction project, you want to know the cost to construct roads connecting some pairs of towns to construct roads, in order to estimate the cost. Among the N(N1)2\frac{N(N − 1)}{ 2 } pairs of towns to construct roads, you want to know the costs of the K cheapest roads.

Write a program which, given the coordinates of the towns of JOI Kingdom and the value of KK, calculates the costs of the KK cheapest roads.

Input Format

In the first line, there are two integers NN and KK.

In the following NN lines, there are two integers XiX_i and YiY_i each line.

Output Format

Output kk lines. In the kk-th line (1kK)1 \leq k \leq K), output the cost of the kk-th cheapest road.

Sample 1

3 2 
-1 0 
0 2
0 0
1
2

The coordinates of the town 11 is (1,0)(−1, 0), the coordinates of the town 22 is (0,2)(0, 2), and the coordinates of the town 33 is (0,0)(0, 0).

There are 3×22=3\frac{3\times 2}{2}=3 pairs of towns.

  • It costs (1)0+02=3|(−1) − 0| + |0 − 2| = 3 yen to construct a road connecting the town 11 and the town 22.
  • It costs (1)0+00=1|(−1) − 0| + |0 − 0| = 1 yen to construct a road connecting the town 11 and the town 33.
  • It costs 00+20=2|0 − 0| + |2 − 0| = 2 yen to construct a road connecting the town 22 and the town 33.

The costs of the roads are 1,2,31, 2, 3 from the cheapest. Therefore, output 11 to the 11-st line, and output 22 to the 22-nd line. This sample input satisfies the constraints of Subtasks 1,4,5,61, 4, 5, 6.

5 4
1 -1
2 0
-1 0
0 2
0 -2
2
2
3
3

Since N=5N=5, there are 5×42=10\frac{5\times 4}{2}=10 pairs of towns.

The costs of the roads are 2,2,3,3,3,3,4,4,4,42, 2, 3, 3, 3, 3, 4, 4, 4, 4 from the cheapest. Therefore, the costs of the 44 cheapest roads are 2,2,3,32, 2, 3, 3.

This sample input satisfies the constraints of Subtasks 1,4,5,61, 4, 5, 6.

4 6
0 0
1 0
3 0
4 0
1
1
2
3
3
4

This sample input satisfies the constraints of Subtasks 1,2,4,5,61, 2, 4, 5, 6.

10 10
10 -8
7 2
7 -8
-3 -6
-2 1
-8 6
8 -1
2 4
6 -6
2 -1

3
3
4
5
6
6
6
7
7
7

This sample input satisfies the constraints of Subtasks 1,4,5,61, 4, 5, 6.

Constraints

For all test data, it is guaranteed that 2N250000, 2\le N\le 250000,~1Kmin(250000,N(N1)2), 1\le K\le\min(250000, \frac{N(N-1)}{2}),~109Xi, Yi109, -10^9\le X_i,~Y_i\le 10^9,~(Xi, Yi)(Xj,Yj)(1i<jN)(X_i,~Y_i)\neq (X_j,Y_j) (1\le i < j\le N)

Subtask# Score Additional Constraints
1 5 N103N\le 10^3
2 6 Yi=0Y_i=0
3 7 K=1K=1
4 20 K10K\le 10
5 27 N105N\le 10^5
6 35 No special constraints