#K50757. Runners Grouping
Runners Grouping
Runners Grouping
You are given n participants with their respective running speeds and a threshold value t. Your task is to determine the minimum number of groups that can be formed such that in each group, the difference between the fastest and the slowest runner does not exceed t.
Detailed Explanation: After sorting the list of speeds in non-decreasing order, you can group the participants greedily. Start with the slowest participant and continue adding participants to the group as long as the difference between the current participant's speed and the group's starting speed does not exceed t. Once the condition fails, form a new group and repeat the process until all participants are grouped.
Mathematical Formulation:
If the sorted speeds are represented as \(s_1, s_2, \dots, s_n\), then a group can be formed as a maximal contiguous sequence \(s_i, s_{i+1}, \dots, s_j\) satisfying \(s_j - s_i \le t\). The goal is to minimize the number of such groups.
inputFormat
The first line contains two integers n and t where n is the number of participants and t is the maximum allowed speed difference within a group.
The second line contains n space-separated integers representing the speeds of the participants.
outputFormat
Output a single integer representing the minimum number of groups required.
## sample5 2
2 3 10 11 8
3