#BS0000314. Xe buýt đón khách (Convention)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 cows arriving at the airport; cow arrives at time . He has arranged buses, each of capacity .
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 , so the buses have enough seats.
Input
- The first line contains three integers , the number of cows, the number of buses, and each bus’s capacity.
- The second line contains integers , the arrival times.
Output
Print one integer, the smallest possible maximum waiting time.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
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.