#K57827. Maximum Valid Groups Formation
Maximum Valid Groups Formation
Maximum Valid Groups Formation
You are given n players with their respective skill levels. Your task is to form as many groups as possible under the following conditions:
- Each group must contain exactly
k
players. - For each group, if you denote the players' skill levels in that group as
s1, s2, \dots, sk
sorted in non-decreasing order, then it must hold that \[ s_k - s_1 \le d, \] whered
is the maximum allowed difference in skill levels. - Each player can be a member of at most one group.
Your goal is to compute the maximum number of valid groups that can be formed.
inputFormat
The first line of input contains three integers n
, k
, and d
separated by spaces, where:
n
is the number of players.k
is the exact number of players that should form a group.d
is the maximum allowed difference in skill levels between the highest and the lowest in a group.
The second line contains n
space separated integers, representing the skill levels of the players.
outputFormat
Output a single integer which is the maximum number of valid groups that can be formed.
## sample8 3 2
4 8 5 6 7 9 5 3
2