#P7561. [JOISC 2021] 道路の建設案 (Road Construction) (Day2)

    ID: 8422 远端评测题 10000ms 2048MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>二分2021优先队列K-D TreeJOI(日本)双指针 two-pointer

[JOISC 2021] 道路の建設案 (Road Construction) (Day2)

Background

10s, 2048M.

Problem Description

The Kingdom of JOI is a x×yx \times y two-dimensional plane. There are nn towns in the kingdom, numbered 1,2,,n1, 2, \cdots, n, and the coordinates of town ii are (xi,yi)(x_i, y_i).

In the Kingdom of JOI, there is a plan to build roads connecting two towns (hereinafter referred to as a “road construction project”). There will be kk roads. Connecting two different towns aa and bb costs xaxb+yayb|x_a − x_b| + |y_a − y_b| yen. If there is already a road connecting cc and dd, then there is no need and it is not allowed to build another road connecting dd and cc, because they are the same.

You need to manage this “road construction project”. To calculate the costs, you need to figure out the costs required to connect some towns. Among these n(n1)2\dfrac{n\cdot(n-1)}{2} possible roads, you want to know the costs of the cheapest kk roads.

Given the coordinates of the towns and kk, compute how much money is needed for the cheapest kk roads.

Input Format

The input consists of n+1n+1 lines.

The first line contains two positive integers n,kn, k. nn is the number of towns, and the meaning of kk is described in the Description section.

Each of the next lines 2n+12 \sim n+1 contains two integers xix_i and yiy_i (1in1 \le i \le n), representing the coordinates of town ii.

Output Format

Output kk lines.

On line kk, output one integer representing the cost in yen of the kk-th cheapest road.

3 2
-1 0
0 2
0 0

1
2

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

2
2
3
3

4 6
0 0
1 0
3 0
4 0

1
1
2
3
3
4

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

Hint

Sample #1 Explanation

There are 3×22=3\dfrac{3 \times 2}{2} = 3 possible choices.

  • Town 11 \to town 22: (1)0+02=3|(-1)-0|+|0-2| = 3 yen.
  • Town 11 \to town 33: (1)0+00=1|(-1)-0|+|0-0| = 1 yen.
  • Town 22 \to town 33: 00+20=2|0-0|+|2-0| = 2 yen.

Sorting them gives 1,2,31, 2, 3, so the output is 11 and 22.

This sample satisfies Subtasks 1,4,5,61, 4, 5, 6.

Sample #2 Explanation

There are 5×42=10\dfrac{5 \times 4}{2} = 10 possible choices.

After sorting, the costs are 2,2,3,3,3,3,4,4,4,42, 2, 3, 3, 3, 3, 4, 4, 4, 4.

This sample satisfies Subtasks 1,4,5,61, 4, 5, 6.

Sample #3 Explanation

This sample satisfies Subtasks 1,2,4,5,61, 2, 4, 5, 6.

Sample #4 Explanation

This sample satisfies Subtasks 1,4,5,61, 4, 5, 6.

Constraints and Notes

This problem uses subtask scoring.

Subtask Score Percentage nn kk yiy_i
11 5%5\% 103\le 10^3 / /
22 6%6\% / =0=0
33 7%7\% =1=1 /
44 20%20\% 10\le 10
55 27%27\% 105\le 10 ^ 5
66 35%35\% /

Note: A slash means there is no special restriction.

For 100%100\% of the testdata:

  • 2n2.5×1052 \le n \le 2.5 \times 10^5.
  • $1 \le k \le \min(2.5 \times 10^5,\ \dfrac{n\cdot(n-1)}{2}$).
  • 109xi,yi109-10^9 \le x_i, y_i \le 10^9, and 1in1 \le i \le n.
  • (xi,yi)(xj,yj)(x_i, y_i)\not = (x_j, y_j) for 1i<jn1 \le i < j \le n.

Notes

This problem is translated from The 20th Japanese Olympiad in Informatics 2020/2021 Spring Training Camp - Contest 2 - T2 Japanese statement.

Translated by ChatGPT 5