编程介的小学生 2020-01-12 14:06 采纳率: 20.5%
浏览 67

Group Travel 的问题

Problem 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<=10^5) 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
3 1
1 11 21
6 2
1 2 4 11 12 14

Sample Output
20
6

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 解决一个加好友限制问题 或者有好的方案
    • ¥15 关于#java#的问题,请各位专家解答!
    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥30 求解达问题(有红包)