#K93687. Team Formation Based on Age Differences
Team Formation Based on Age Differences
Team Formation Based on Age Differences
You are given a group of n people each with a specific age. Your task is to organize these people into teams such that:
- The ages in each team (when sorted in ascending order) are consecutive.
- For each team, the difference between the youngest and the oldest member does not exceed a given value \(k\), i.e. \(a_{max} - a_{min} \le k\).
Determine the minimum number of teams required to organize all participants under these conditions.
Note: Each team is formed greedily by taking as many consecutive people (after sorting the ages) as possible while satisfying the condition.
inputFormat
The input is given via standard input and contains two lines:
- The first line contains two integers n and k where n is the number of people and k is the maximum allowed age difference within a team.
- The second line contains n space-separated integers representing the ages of the people.
outputFormat
Output a single integer representing the minimum number of teams required.
## sample6 3
1 2 3 6 7 10
3
</p>