编程介的小学生 2019-04-22 09:29 采纳率: 20.5%
浏览 175

计算对于所有人来说最短的旅行距离的和,怎么利用 C 语言的程序的编写的办法来实现的

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 Matlab问题解答有两个问题
    • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
    • ¥15 stm32的can接口不能收发数据
    • ¥15 目标检测算法移植到arm开发板
    • ¥15 利用JD51设计温度报警系统
    • ¥15 快手联盟怎么快速的跑出建立模型