#abc334f. F - Christmas Present 2

    ID: 2946 传统题 1000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>来源atcoder动态规划数据结构单调队列基础算法前缀和与差分

F - Christmas Present 2

Score : 550550 points

问题描述

在一个以 xyxy-坐标系表示的城镇中,圣诞老人和编号从 11NNNN 个孩子居住在一起。圣诞老人的房子位于坐标 (SX,SY)(S_X,S_Y),而第 ii1iN1\leq i\leq N)个孩子的房子位于坐标 (Xi,Yi)(X_i,Y_i)

圣诞老人希望按照数值顺序给这 NN 个孩子每人送一个礼物。为了给第 ii 个孩子送礼物,圣诞老人必须至少携带一份礼物前往该孩子的房子。但是,圣诞老人每次最多只能携带 KK 份礼物,并且在礼物用完后他必须返回自己的房子补充礼物(圣诞老人的房子里有足够的礼物)。

请计算圣诞老人从自己家出发,给所有 NN 个孩子送出礼物并返回自己家所需的最短距离。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a town represented as an xyxy-plane, where Santa lives, along with NN children numbered 11 to NN. Santa's house is at coordinates (SX,SY)(S_X,S_Y), and the house of child i (1iN)i\ (1\leq i\leq N) is at (Xi,Yi)(X_i,Y_i).

Santa wants to deliver one present to each of the NN children in numerical order. To deliver a present to child ii, Santa must visit the house of child ii with at least one present in hand. However, Santa can only carry up to KK presents at a time, and he must return to his own house to replenish presents (there are enough presents at Santa's house).

Find the minimum distance Santa must travel to leave his house, deliver presents to all NN children, and return to his house.

Constraints

  • 1KN2×1051\leq K\leq N \leq 2\times 10^5
  • 109SX,SY,Xi,Yi109-10^9\leq S_X,S_Y,X_i,Y_i \leq 10^9
  • (SX,SY)(Xi,Yi)(S_X,S_Y)\neq (X_i,Y_i)
  • (Xi,Yi)(Xj,Yj) (ij)(X_i,Y_i)\neq (X_j,Y_j)\ (i\neq j)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN KK

SXS_X SYS_Y

X1X_1 Y1Y_1

X2X_2 Y2Y_2

\vdots

XNX_N YNY_N

Output

Print the minimum distance Santa must travel. The output will be considered correct if the absolute or relative error from the true value is at most 10610^{−6}.

Sample Input 1

3 2
1 1
3 1
1 2
3 2

Sample Output 1

9.236067977499790

In the figure above, the red circle represents Santa's house, and the circles with numbers represent the houses of the children with those numbers.

Consider Santa acting as follows:

  1. Leave his house with two presents.
  2. Go to child 11's house and deliver a present.
  3. Return to his house and replenish one present.
  4. Go to child 22's house and deliver a present.
  5. Go to child 33's house and deliver a present.
  6. Return to his house.

In this case, Santa travels the distance of 2+2+1+2+5=7+5=9.2362+2+1+2+\sqrt{5}=7+\sqrt{5}=9.236\dots, which is the minimum.

Sample Input 2

2 1
0 1
-1 1
1 1

Sample Output 2

4.000000000000000

Sample Input 3

8 3
735867677 193944314
586260100 -192321079
95834122 802780784
418379342 -790013317
-445130206 189801569
-354684803 -49687658
-204491568 -840249197
853829789 470958158
-751917965 762048217

Sample Output 3

11347715738.116592407226562

update @ 2024/3/10 01:22:14