COCI '12 Contest 4 #4 Razlika

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 0.5s
Memory limit: 64M

Problem type

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 Specification

The first line of input contains two positive integers, N (3N1000000) and K (1KN2).

The second line of input contains N space-separated positive integers – the sequence V (5000000Vi5000000).

Output Specification

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

Sample Input 1

Copy
5 2
-3 -2 3 8 6

Sample Output 1

Copy
7

Sample Input 2

Copy
6 2
-5 8 10 1 13 -1

Sample Output 2

Copy
13

Sample Input 3

Copy
6 3
10 2 8 17 2 17

Sample Output 3

Copy
6

Comments

There are no comments at the moment.