Pro.ID21816 TitleGroup Travel Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21816 AC2 Submit14 Ratio14.29% 时间&空间限制描述After finished the composition exam of GRE, Sigma and QK wanted to have a good rest, and then invented all member of ACM-BUAA team to go to a trip. After some hard work, they find a bus for vehicle in the trip. Unfortunately, not all the people in ACM-BUAA team want to go to the same place, so the bus must parking at some place. But as we know, the traffic is always bad, so they decided only parking on some place. You can assume all where they want to go is on positive number axis, and Beihang University is on the origin. There are N people on the ACM-BUAA team. The ith people want to the place pi. For some reason, they didn't want the number of parking times exceed K. Because all of them are busy preparing the trip, when they realize the parking-problem, it's too late for them to coding. So they ask you for help, can you minimize the sum of the walking distance for all the people? 输入Input includes multiple cases. First line is the number of case t. For each case: The first line contain two integer number N, K ( 0 < K ≤ N ≤ 3000 ). The second line contains N numbers, which means pi ( 0 ≤ pi ≤ 105 ) mentioned before. 输出Description After finished the composition exam of GRE, Sigma and QK wanted to have a good rest, and then invented all member of ACM-BUAA team to go to a trip. After some hard work, they find a bus for vehicle in the trip. Unfortunately, not all the people in ACM-BUAA team want to go to the same place, so the bus must parking at some place. But as we know, the traffic is always bad, so they decided only parking on some place. You can assume all where they want to go is on positive number axis, and Beihang University is on the origin. There are N people on the ACM-BUAA team. The ith people want to the place pi. For some reason, they didn't want the number of parking times exceed K. Because all of them are busy preparing the trip, when they realize the parking-problem, it's too late for them to coding. So they ask you for help, can you minimize the sum of the walking distance for all the people? Input Input includes multiple cases. First line is the number of case t. For each case: The first line contain two integer number N, K ( 0 < K ≤ N ≤ 3000 ). The second line contains N numbers, which means pi ( 0 ≤ pi ≤ 105 ) mentioned before. Output For each case: Output an integer number. It is the minimal sum of the walking distance for all the people. Sample Input 2 Sample Output 20 Source 样例输入2 样例输出20 作者 |