Minimize Distance
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题面翻译
每组数据:n,k
1个长度为n的数组
数组中的一个元素 代表在数轴上 的位置有一个仓库。
刚开始你位于 0 ,手上有n个货物,要把他们放到每个仓库中,但是每次你最多能拿k个货物,把他们放到仓库之后你要回到原点0拿取新的货物。最后一趟不用返回。
问题是你最少需要走多远能把所有物品放进仓库。
题目描述
A total of depots are located on a number line. Depot lies at the point for .
You are a salesman with bags of goods, attempting to deliver one bag to each of the depots. You and the bags are initially at the origin . You can carry up to bags at a time. You must collect the required number of goods from the origin, deliver them to the respective depots, and then return to the origin to collect your next batch of goods.
Calculate the minimum distance you need to cover to deliver all the bags of goods to the depots. You do not have to return to the origin after you have delivered all the bags.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases ( ). Description of the test cases follows.
The first line of each test case contains two integers and ( ).
The second line of each test case contains integers ( ). It is possible that some depots share the same position.
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output a single integer denoting the minimum distance you need to cover to deliver all the bags of goods to the depots.
样例 #1
样例输入 #1
4
5 1
1 2 3 4 5
9 3
-5 -10 -15 6 5 8 3 7 4
5 3
2 2 3 3 3
4 2
1000000000 1000000000 1000000000 1000000000
样例输出 #1
25
41
7
3000000000
提示
In the first test case, you can carry only one bag at a time. Thus, the following is a solution sequence that gives a minimum travel distance: $ 0 \to 2 \to 0 \to 4 \to 0 \to 3 \to 0 \to 1 \to 0 \to 5 $ , where each means you go the origin and grab one bag, and each positive integer means you deliver the bag to a depot at this coordinate, giving a total distance of units. It must be noted that there are other sequences that give the same distance.
In the second test case, you can follow the following sequence, among multiple such sequences, to travel minimum distance: $ 0 \to 6 \to 8 \to 7 \to 0 \to 5 \to 4 \to 3 \to 0 \to (-5) \to (-10) \to (-15) $ , with distance . It can be shown that is the optimal distance for this test case.