#P17319. [ICPC 2018 Nanjing R] Tournament
[ICPC 2018 Nanjing R] Tournament
题目描述
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.
5 2
0 4 7 9 10
7
9 3
0 1 10 11 20 21 22 30 32
23