- Time limit: 1.00 s
- Memory limit: 512 MB
There are houses on a street, numbered . The distance of houses and is . You know the number of children in each house.
Your task is to establish schools in such a way that each school is in some house. Then, each child goes to the nearest school. What is the minimum total walking distance of the children if you act optimally?
Input
The first input line has two integers and : the number of houses and the number of schools. The houses are numbered .
After this, there are integers : the number of children in each house.
Output
Print the minimum total distance.
Constraints
Example
Input:
6 2 2 7 1 4 6 4
Output:
11
Explanation: Houses 2 and 5 will have schools.