#P17319. [ICPC 2018 Nanjing R] Tournament
[ICPC 2018 Nanjing R] Tournament
Problem Description
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 .
Input Format
The first line contains two positive integers ().
The second line contains non-negative integers ().
Output Format
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