#P13416. [COCI 2012/2013 #4] RAZLIKA

    ID: 15290 远端评测题 500ms 64MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学贪心2012单调队列排序差分COCI(克罗地亚)

[COCI 2012/2013 #4] RAZLIKA

题目描述

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

输入格式

The first line of input contains two positive integers, NN (3N10000003 \leq N \leq 1\,000\,000) and KK (1KN21 \leq K \leq N - 2).

The second line of input contains NN space-separated positive integers – the sequence VV (5000000Vi5000000-5\,000\,000 \leq V_i \leq 5\,000\,000).

输出格式

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

5 2
-3 -2 3 8 6
7
6 2
-5 8 10 1 13 -1
13
6 3
10 2 8 17 2 17
6