QOJ.ac

QOJ

実行時間制限: 0.5 s メモリ制限: 64 MB 満点: 120

#16640. RAZLIKA

統計

Mirko最新的数学作业非常难!给定一个由 $N$ 个整数组成的序列 $V$,从中恰好移除 $K$ 个数。令 $M$ 为剩下数字中任意两个数之间的最大差值,而 $m$ 为剩下数字中任意两个数之间的最小差值。我们需要从 $V$ 中选择 $K$ 个整数移除,使得 $M + m$ 的和尽可能小。Mirko不太擅长数学,所以他请求你来帮助他!

输入格式

输入的第一行包含两个正整数 $N$ ($3 \le N \le 1\,000\,000$) 和 $K$ ($1 \le K \le N - 2$)。

第二行包含 $N$ 个空格分隔的整数,表示序列 $V$ ($-5\,000\,000 \le V_i \le 5\,000\,000$)。

输出格式

输出的第一行,也是唯一的一行,应包含 $M + m$ 的最小可能值。

样例

输入样例 1

5 2 
-3 -2 3 8 6

输出样例 1

7

输入样例 2

6 2 
-5 8 10 1 13 -1

输出样例 2

13

输入样例 3

6 3 
10 2 8 17 2 17

输出样例 3

6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.