题目描述
Problem Description
There are $ N $ members in the club called Paken. Each member is numbered from $ 1 $ to $ N $ in order of their age.
The competitive programming skill of member $ i $ is $ A_i $.
In competitive programming, team battles are common. Paken defines the "team combat power" as the value of the lowest skill level in the team.
For example, the combat power of a team with members having skills $ 5 $, $ 4 $, and $ 10 $ is $ 4 $.
Suddenly, competitive programming was added as an event in the 2020 Tokyo Olympics, which requires teams of exactly $ D $ members.
All members of Paken want to apply for the selection. Therefore, Paken decided to divide the teams as follows:
- Allow as many people as possible to apply for the selection.
- Maximize the total team combat power.
- No person can be in multiple teams.
What will be the total team combat power?
Input Format
The input is given from the standard input in the following format:
$ N $ $ D $ $ A_1 $ $ A_2 $ $ A_3 $ ... $ A_N $
Output Format
Output the total team combat power as an integer on one line according to the method described in the problem.
Sample Input and Output
Sample Input #1
4 2
20 18 12 24
Sample Output #1
32
Sample Input #2
5 5
8 6 9 1 20
Sample Output #2
1
Sample Input #3
6 8
1268 1755 2315 1071 1229 1101
Sample Output #3
0
Sample Input #4
8 3
1345 1355 1390 1285 1171 936 1272 855
Sample Output #4
2516
Notes/Hints
Constraints
- $ N $ is an integer between $ 1 $ and $1\ 000$ inclusive.
- $ D $ is an integer between $ 1 $ and $ 10 $ inclusive.
- $ A_i $ is an integer between $ 1 $ and $4\ 208$ inclusive.
- There are no members with the same skill level.
Subtasks
Subtask $ 1 $ \[$ 25 $ points\]
- Satisfies $ N = D $.
Subtask $ 3 $ \[$ 75 $ points\]
- No additional constraints.
Sample Explanation 1
The skills of the members are $ {20, 18, 12, 24} $ from member $ 1 $ onwards. If the teams are decided as follows, the total combat power is $ 20 + 12 = 32 $.
- Team consisting of members $ 1 $ and $ 4 $: Combat power is $ min(20, 24) = 20 $.
- Team consisting of members $ 2 $ and $ 3 $: Combat power is $ min(18, 12) = 12 $.
Sample Explanation 2
Since $ N = D $, only one team can be formed, and all members can participate in the selection without any excess or shortage. Therefore, the total combat power is $ min(8, 6, 9, 1, 20) = 1 $.
Sample Explanation 3
Since $ N < D $, no teams can be formed. Therefore, the total combat power is $ 0 $.
Sample Explanation 4
Since $ 8 $ members are to be divided into $ 3 $ member teams, $ 2 $ members will inevitably be left out.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分