#P5119. Cow Bus Scheduling

    ID: 18357 Type: Default 1000ms 256MiB

Cow Bus Scheduling

Cow Bus Scheduling

Farmer John is hosting a unique "Cow Grazing Festival" at his farm! Cows from all over the world will fly in and attend the event. In particular, there are \(N\) cows arriving at the local airport at times \(t_i\) (\(0 \le t_i \le 10^9\)). To transport them, Farmer John has arranged \(M\) buses, and each bus can carry up to \(C\) cows (with \(1 \le C \le N\)).

The buses depart as soon as the last cow assigned to that bus arrives. A cow's waiting time is defined as the difference between her arrival time and her bus's departure time. Farmer John wants to minimize the maximum waiting time experienced by any cow. What is the smallest possible maximum waiting time if the cows are optimally assigned to the buses? It is guaranteed that \(MC \ge N\).

inputFormat

The first line contains three space-separated integers: \(N\) (the number of cows), \(M\) (the number of buses), and \(C\) (the capacity of each bus).

The second line contains \(N\) space-separated integers \(t_1, t_2, \dots, t_N\) representing the arrival times of the cows.

outputFormat

Output a single integer that represents the minimum possible maximum waiting time among all cows.

sample

6 3 2
1 2 4 6 7 9
2