1946: 邮局

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

   有一条笔直的公路,公路旁有村庄。公路用整数轴表示,每个村庄的位置用一个整数坐标表示。没有两个村庄位于同一位置。两个位置之间的距离是其整数坐标差的绝对值。
    为了方便交流,准备在村庄上建邮局,但不一定所有村庄都建邮局,一个村庄和里面的邮局有着相同的位置。在修建邮局时,应选择其位置,使每个村庄与其最近邮局之间的所有距离之和最小。
    你要编写一个程序,根据村庄的位置和邮局的数量,计算每个村庄与其最近邮局之间所有距离的最小可能总和。




There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each village is identified with a single integer coordinate. There are no two villages in the same position. The distance between two positions is the absolute value of the difference of their integer coordinates.

Post offices will be built in some, but not necessarily all of the villages. A village and the post office in it have the same position. For building the post offices, their positions should be chosen so that the total sum of all distances between each village and its nearest post office is minimum.

You are to write a program which, given the positions of the villages and the number of post offices, computes the least possible sum of all distances between each village and its nearest post office.


输入格式

输入第一行包含两个整数:第一行是村庄数量V,1<=V<=300,第二行是邮局数量P,1<=P<=30,P<=V。第二行包含V个整数,按升序排列。这V个整数是村庄的位置。对于每个位置X,它保持1<=X<=10000

输出格式

包含一个整数S,这是每个村庄与其最近邮局之间所有距离的总和。

输入样例 复制

10 5
1 2 3 6 7 9 11 22 44 50

输出样例 复制

9