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

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

[COCI 2012/2013 #4] RAZLIKA

[COCI 2012/2013 #4] RAZLIKA

题目描述

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!

输入格式

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

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

输出格式

The first and only line of output must contain the smallest possible sum $M + 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

提示

(暂无提示) 标签: P13416|数学|贪心|2012|单调队列|排序|差分|COCI(克罗地亚)

来源

P13416|[COCI 2012/2013 #4] RAZLIKA