#C1308. Minimize Groups of Runners

    ID: 42578 Type: Default 1000ms 256MiB

Minimize Groups of Runners

Minimize Groups of Runners

In this problem, you are given the number of runners ( n ), a list of their speeds, and an integer ( k ) representing the maximum allowed difference in speed within a group. Your task is to partition the runners into the minimum number of groups such that the difference between the fastest and the slowest runner in each group does not exceed ( k ).

To solve the problem, you can sort the list of speeds and then iterate over it, grouping runners together until the next runner's speed would exceed the allowed range, at which point you start a new group. This ensures that each group conforms to the requirement.

inputFormat

The input is read from standard input (stdin) and consists of three lines:
1. The first line contains a single integer ( n ), the number of runners.
2. The second line contains ( n ) space-separated integers representing the speeds of the runners.
3. The third line contains a single integer ( k ), the maximum allowed difference within any group.

outputFormat

Output to standard output (stdout) a single integer representing the minimum number of groups required.## sample

1
5
3
1