100 atcoder#ABC181E. [ABC181E] Transformable Teacher
[ABC181E] Transformable Teacher
Score : points
Problem Statement
There are children in a kindergarten. The height of the -th child is . Here, is an odd number.
You, the teacher, and these children - people in total - will make pairs.
Your objective is to minimize the sum of the differences in height over those pairs. That is, you want to minimize , where is the pair of heights of people in the -th pair.
You have forms that you can transform into. Your height in the -th form is .
Find the minimum possible sum of the differences in height over all pairs, achieved by optimally choosing your form and making pairs.
Constraints
- All values in input are integers.
- is an odd number.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible sum of the differences in height over all pairs, achieved by optimally choosing your form and making pairs.
5 3
1 2 3 4 7
1 3 8
3
The minimum is minimized by choosing the form with the height and making pairs with heights , , and .
7 7
31 60 84 23 16 13 32
96 80 73 76 87 57 29
34
15 10
554 525 541 814 661 279 668 360 382 175 833 783 688 793 736
496 732 455 306 189 207 976 73 567 759
239