luogu#P5119. [USACO18DEC] Convention S

[USACO18DEC] Convention S

Problem Description

A unique cow grass-eating convention is about to be held at Farmer John’s farm.

Cows from all over the world will arrive at the local airport to attend the convention and eat grass. Specifically, there are NN cows arriving at the airport (1N1051\le N\le 10^5), and cow ii arrives at time tit_i (0ti1090\le t_i\le 10^9). Farmer John has arranged MM buses (1M1051\le M\le 10^5) to pick up these cows at the airport. Each bus can carry CC cows (1CN1\le C\le N). Farmer John is waiting at the airport and plans to assign arriving cows to buses. When the last cow assigned to a bus arrives, that bus can depart. Farmer John wants to be a good host, so he does not want the cows to wait at the airport for too long. If Farmer John schedules the buses optimally, what is the minimum possible value of the maximum waiting time among all cows? A cow’s waiting time is the difference between her arrival time and the departure time of the bus she takes.

The input guarantees that MCNMC\ge N.

Input Format

The first line contains three space-separated integers NN, MM, and CC. The second line contains NN space-separated integers, representing the arrival time of each cow.

Output Format

Output one line containing the minimum possible value of the maximum waiting time among all arriving cows.

6 3 2
1 1 10 14 4 3
4

Hint

If two cows arriving at time 11 take the first bus, the cows arriving at times 33 and 44 take the second bus, and the cows arriving at times 1010 and 1414 take the third bus, then the cow with the longest waiting time waits for 44 units of time (the cow arriving at time 1010 waits from time 1010 until time 1414).

Translated by ChatGPT 5