CF427E.Police Patrol

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

假设你的城市是一个无限延展的二维平面,其上建立了笛卡尔坐标系。你所在城市的唯一一条受犯罪影响的道路是 xx 轴。目前,这条道路上共有 nn 名罪犯。该道路上尚未建立任何警察局,因此市长希望在此处新建一座警察局。

由于你将负责管理这座新建的警察局,市长要求你选择一个合适的位置(某个整数坐标点)来建造它。你需要为警察局选定最优位置,以最小化你抓捕所有罪犯所需的总时间。整个抓捕任务将仅从该警察局出发执行。

新建的警察局仅配备一辆巡逻车。你将驾驶该车前往罪犯所在地,将他们带上车,再将他们送回警察局并关入监狱。巡逻车每次最多可搭载 mm 名罪犯。注意:罪犯并不知晓你的抓捕行动,因此他们会原地不动,不会逃跑。

你的任务是确定警察局的建造位置,使得抓捕所有罪犯所需行驶的总路程尽可能小。注意:你也可以将警察局建在已有罪犯所在的坐标点上;此时,位于该点的所有罪犯将被立即逮捕。

输入格式

The first line of the input will have two integers n (1 ≤ n ≤ 106) and m (1 ≤ m ≤ 106) 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 109. 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++.

输入的第一行包含两个整数 nn(1≤n≤1061 \leq n \leq 10^6)和 mm(1≤m≤1061 \leq m \leq 10^6),以空格分隔。
下一行包含 nn 个以空格分隔的整数。其中第 ii 个整数表示第 ii 个罪犯在 xx 轴上的位置。位置的绝对值不超过 10910^9。若某罪犯的位置为 xx,则其位于平面上的点 (x, 0)(x,\, 0) 处。

罪犯的位置将以非递减顺序给出。注意:平面上的某一点处可能有多个罪犯。

注意:由于输入/输出规模可能非常大,请勿在你的编程语言中使用低效的输入/输出方式。例如,在 C++ 中请勿使用输入/输出流(cin、cout)。

输出格式

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

输入解题思路,AI测评打分。不知道怎么写?

首页