PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000314. Xe buýt đón khách (Convention)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xe buýt đón khách (Convention)

Convention

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Farmer John is hosting a convention at his farm. There are NN cows arriving at the airport; cow ii arrives at time tit_i. He has arranged MM buses, each of capacity CC.

Assign every cow to exactly one bus. A bus can depart as soon as all cows assigned to it have arrived. A cow’s waiting time is its bus departure time minus its arrival time. Some buses may remain unused.

Find the minimum possible maximum waiting time among all cows. It is guaranteed that MC≥NMC\ge N, so the buses have enough seats.

Input

  • The first line contains three integers N,M,CN,M,C, the number of cows, the number of buses, and each bus’s capacity.
  • The second line contains NN integers t1,…,tNt_1,\ldots,t_N, the arrival times.

Output

Print one integer, the smallest possible maximum waiting time.

Subtasks

  • Subtask 1 (20 points): 1≤N≤121\le N\le12; 1≤M≤121\le M\le12; 1≤C≤N1\le C\le N; 0≤ti≤300\le t_i\le30; MC≥NMC\ge N.
  • Subtask 2 (30 points): 1≤N,M≤1051\le N,M\le10^5; 1≤C≤N1\le C\le N; 0≤ti≤1090\le t_i\le10^9; MC≥NMC\ge N; M=1M=1.
  • Subtask 3 (50 points): 1≤N,M≤1051\le N,M\le10^5; 1≤C≤N1\le C\le N; 0≤ti≤1090\le t_i\le10^9; MC≥NMC\ge N.

Examples

Input 1

6 3 2
1 1 10 14 4 3

Output 1

4

Explanation

Sorted arrivals: 1,1,3,4,10,14. Pair consecutive cows; the last bus has wait 4. With cap 3 the last cow cannot be paired.