cho.sh
Notes
Loading...

Backup

Time limit

2s

Memory limit

128 MB

Problem

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.

Input

The first line contains the number of companies n and the number of available cables k.

  • 2 <= n <= 100000
  • 1 <= k <= n / 2

Each of the next n lines contains one company position s.

  • 0 <= s <= 1000000000
  • The positions are given in increasing order.
  • No two companies are at the same position.

Output

Output one integer: the minimum possible sum of cable lengths when 2k distinct companies are connected as k pairs.