logo AlgoBeat OnlineJudge
登录 注册

#217531. [ICPC 2018 Nanjing R] Tournament

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are villagers (including the village chief) living in Number Village. Interestingly, all of their houses lie on a straight line. The house of the -th villager () lies exactly kilometers to the east of the village chief's house. (For simplicity, the -th villager is the village chief, so .)

Recently, a tournament is going to be held in Number Village, in which everyone in the village will participate.

For the convenience of villagers, the organizer plans to build stadiums. The stadium can be built anywhere in the village, even at the same place as any villager's house.

However, the organizer wants the traffic cost to be minimized. The traffic cost is defined by , where is the distance between the -th villager's house and the -th stadium.

Your task is to calculate the minimal traffic cost (rounded down to the nearest integer), given and .

输入格式

The first line contains two positive integers ().

The second line contains non-negative integers ().

输出格式

Print a single integer the minimal traffic cost rounded down to the nearest integer.

样例

样例输入 1

5 2
0 4 7 9 10

样例输出 1

7

样例输入 2

9 3
0 1 10 11 20 21 22 30 32

样例输出 2

23