308885: CF1591C. Minimize Distance
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Minimize Distance
题意翻译
一条线上有 $n$ ($1 \le n \le 2 \cdot 10^5$)个仓库,第 $i$ 个仓库的位置是 $x_i$ ($1 \le i \le n$)。 你有 $n$ 箱货物,要分别运到这 $n$ 个仓库里。你的初始位置在点 $0$ ,一次可以携带 $k$ ($1 \le k \le n$) 箱货物。在送完携带的所有货物后,需要返回点 $0$ 去取货物。 请求出送完所有货物时走的最短路程。题目描述
A total of $ n $ depots are located on a number line. Depot $ i $ lies at the point $ x_i $ for $ 1 \le i \le n $ . You are a salesman with $ n $ bags of goods, attempting to deliver one bag to each of the $ n $ depots. You and the $ n $ bags are initially at the origin $ 0 $ . You can carry up to $ k $ 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 $ t $ ( $ 1 \le t \le 10\,500 $ ). Description of the test cases follows. The first line of each test case contains two integers $ n $ and $ k $ ( $ 1 \le k \le n \le 2 \cdot 10^5 $ ). The second line of each test case contains $ n $ integers $ x_1, x_2, \ldots, x_n $ ( $ -10^9 \le x_i \le 10^9 $ ). It is possible that some depots share the same position. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
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
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