Swimming Competition
Time limit1sMemory limit1024 MB
Split a sorted list of N swimmer times into consecutive heats of size A to B, minimizing the largest within-heat gap between fastest and slowest.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Dynamic programming, Array
- Solved
- No attempts yet
Problem
Any student who wishes may take part in the open student swimming competition. Because there is no advance registration, the organizers never know beforehand how many contestants will show up.
The pool has 8 lanes, but this time fewer students arrived than expected, so the organizers decided to split them into smaller heats of no fewer than and no more than swimmers each.
The organizers also want every race to be as exciting as possible, with swimmers of similar ability competing together.
Write a program that assigns the arriving students to heats so that the largest value — taken over all heats — of the absolute difference between the slowest swimmer's and the fastest swimmer's average finishing time within a heat is as small as possible.
Input
The first line contains three space-separated integers: the number of participants who arrived , and the minimum and maximum number of swimmers allowed in one heat.
Each of the next lines contains a time , the average time in which a swimmer covers the distance, given in non-decreasing order ().
The input is always such that a valid split into heats exists.
Output
Over all valid ways to split every participant into heats, consider the largest difference, within a single heat, between the slowest and the fastest swimmer's time. Print the smallest value this maximum can take, as a single integer.