302229: CF427E. Police Patrol

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Police Patrol

题意翻译

## 题面描述 在一条数轴上有 $n$ $(1<=n<=10^6)$ 个罪犯,第 $i$ 个罪犯的坐标为 $a_i$ $(\left|a_i\right|<=10^9)$ 。警察们要选择一个地点作为警察局。他们有一辆警车,可容纳 $m$ $(1<=m<=10^6)$ 个罪犯。那么问题来了,把警察局建在哪能使警察抓捕这些罪犯的行程总和最短。 注意:罪犯**不会**逃走。 ## 输入格式 第一行两个整数 $n$ , $m$ 。分别为罪犯个数和警车容纳罪犯个数。 第二行 $n$ 个整数,为罪犯的坐标。 ## 输出格式 输出一个数,即最短行程和。

题目描述

Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the $ x $ -axis. Currently, there are $ n $ criminals along the road. No police station has been built on this road yet, so the mayor wants to build one. As you are going to be in charge of this new police station, the mayor has asked you to choose a suitable position (some integer point) for building it. You should choose the best position for the police station, so that you could minimize the total time of your criminal catching mission. Your mission of catching the criminals will operate only from this station. The new station will have only one patrol car. You will go to the criminals by this car, carry them on the car, bring them back to the police station and put them in prison. The patrol car can carry at most $ m $ criminals at a time. Note that, the criminals don't know about your mission. So, they will stay where they are instead of running away. Your task is to find the position for the police station, so that total distance you need to cover to catch all the criminals will be minimum possible. Note that, you also can built the police station on the positions where one or more criminals already exist. In such a case all these criminals are arrested instantly.

输入输出格式

输入格式


The first line of the input will have two integers $ n (1<=n<=10^{6}) $ and $ m (1<=m<=10^{6}) $ separated by spaces. The next line will contain $ n $ integers separated by spaces. The $ i^{th} $ integer is the position of the $ i^{th} $ criminal on the $ x $ -axis. Absolute value of positions will not exceed $ 10^{9} $ . If a criminal has position $ x $ , he/she is located in the point $ (x,0) $ of the plane. The positions of the criminals will be given in non-decreasing order. Note, that there can be more than one criminal standing at some point of the plane. Note: since the size of the input/output could be very large, don't use slow input/output techniques in your language. For example, do not use input/output streams (cin, cout) in C++.

输出格式


Print a single integer, that means the minimum possible distance you need to cover to catch all the criminals.

输入输出样例

输入样例 #1

3 6
1 2 3

输出样例 #1

4

输入样例 #2

5 5
-7 -6 -3 -1 1

输出样例 #2

16

输入样例 #3

1 369
0

输出样例 #3

0

输入样例 #4

11 2
-375 -108 1336 1453 1598 1892 2804 3732 4291 4588 4822

输出样例 #4

18716

Input

题意翻译

## 题面描述 在一条数轴上有 $n$ $(1<=n<=10^6)$ 个罪犯,第 $i$ 个罪犯的坐标为 $a_i$ $(\left|a_i\right|<=10^9)$ 。警察们要选择一个地点作为警察局。他们有一辆警车,可容纳 $m$ $(1<=m<=10^6)$ 个罪犯。那么问题来了,把警察局建在哪能使警察抓捕这些罪犯的行程总和最短。 注意:罪犯**不会**逃走。 ## 输入格式 第一行两个整数 $n$ , $m$ 。分别为罪犯个数和警车容纳罪犯个数。 第二行 $n$ 个整数,为罪犯的坐标。 ## 输出格式 输出一个数,即最短行程和。

加入题单

上一题 下一题 算法标签: