Time limit
2s
Memory limit
128 MB
Several companies are located at distinct positions on one straight road. You must use exactly k network cables to connect 2k distinct companies as k pairs.
A company cannot belong to more than one pair. The cable length needed for one pair is the distance between the two companies.
Choose and pair the companies so that the sum of the k cable lengths is as small as possible, and output that minimum total length.
The first line contains the number of companies n and the number of available cables k.
2 <= n <= 1000001 <= k <= n / 2Each of the next n lines contains one company position s.
0 <= s <= 1000000000Output one integer: the minimum possible sum of cable lengths when 2k distinct companies are connected as k pairs.