K Balanced Teams

题意翻译

*题目名称:旗鼓相当的队友Ⅱ* ## 题目描述 您是本地大学的教练,有$n$位选手在你这里学习,并且已知第$i$位的能力值为$a_i$。 现在您需要挑选出若干位选手组成至多$k$支队伍。众所周知,参赛的人数越多,你的大学获胜的概率越大。所以,你需要使得你选出的至多$k$支(至少$1$支)**非空**队伍的**总人数**最多。但是,你知道**每支**队伍中队员们的实力应当*差不多*,这意味着对于**任意**一支队伍,不应当存在两名实力值相差超过$5$的选手。所有的队伍都是相互独立的(这意味着我们不考虑来自两只不同队伍的选手的实力值差距)。 可能有的选手不属于任何一支队伍。 您的任务是求出满足以上要求的至多$k$(至少$1$)支**非空**队伍的**总人数**。 **如果您是一名Python选手,您可以考虑在提交代码时选择`PyPy`而不是`Python`**。 ## 输入输出格式 ### 输入格式: 输入文件的第一行包含两个整数$n$和$k$,代表选手总数和队伍数量上限; 第二行输入$n$个整数$a_1, a_2, \ldots a_n$,第$i$个整数代表第$i$位选手的实力值。 ### 输出格式: 输出文件仅包含一行,包含一个整数——至多$k$(至少$1$)支满足上述要求的队伍的**总人数的最大值**。 ## 说明: 对于所有数据,$1 \leq k \leq n \leq 5000, 1 \leq a_i \leq 10^9$。 **如果您是一名Python选手,您可以考虑在提交代码时选择`PyPy`而不是`Python`**。

题目描述

You are a coach at your local university. There are $ n $ students under your supervision, the programming skill of the $ i $ -th student is $ a_i $ . You have to form $ k $ teams for yet another new programming competition. As you know, the more students are involved in competition the more probable the victory of your university is! So you have to form no more than $ k $ (and at least one) non-empty teams so that the total number of students in them is maximized. But you also know that each team should be balanced. It means that the programming skill of each pair of students in each team should differ by no more than $ 5 $ . Teams are independent from one another (it means that the difference between programming skills of two students from two different teams does not matter). It is possible that some students not be included in any team at all. Your task is to report the maximum possible total number of students in no more than $ k $ (and at least one) non-empty balanced teams. If you are Python programmer, consider using PyPy instead of Python when you submit your code.

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ k $ ( $ 1 \le k \le n \le 5000 $ ) — the number of students and the maximum number of teams, correspondingly. The second line of the input contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 10^9 $ ), where $ a_i $ is a programming skill of the $ i $ -th student.

输出格式


Print one integer — the maximum possible total number of students in no more than $ k $ (and at least one) non-empty balanced teams.

输入输出样例

输入样例 #1

5 2
1 2 15 15 15

输出样例 #1

5

输入样例 #2

6 1
36 4 1 25 9 16

输出样例 #2

2

输入样例 #3

4 4
1 10 100 1000

输出样例 #3

4