Problem list
Log in
#coci00254 · COCI 2012/2013 Contest 4

Razlika

Platinum IV 0.5 s 64 MB

Mirko's newest math homework assignment is a very difficult one! Given a sequence, V, of N integers, remove exactly K of them from the sequence. Let M be the largest difference of any two remaining numbers in the sequence, and m the smallest such difference. Select the K integers to be removed from V in such a way that the sum $M + m$ is the smallest possible. Mirko isn't very good at math, so he has asked you to help him!

Input

The first line of input contains two positive integers, N ($3 \le N \le 1,000,000$) and K ($1 \le K \le N - 2$). The second line of input contains N space-separated positive integers – the sequence V (-5 000 000 ≤ $V_{i} \le 5,000,000$).

Output

The first and only line of output must contain the smallest possible sum $M + m$.

Example 1

Input
5 2
-3 -2 3 8 6
Output
7

Example 2

Input
6 2
-5 8 10 1 13 -1
Output
13

Example 3

Input
6 3
10 2 8 17 2 17
Output
6
Source
COCI 2012/2013 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code