#BS0000318. Chia đoàn tàu hàng (Freight Train)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia đoàn tàu hàng (Freight Train)
Freight Train
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A freight train arrives in Belgium from the Netherlands, but some cargo must continue to Luxembourg. The train has wagons numbered through in order. Exactly wagons carry cargo for Luxembourg; all others are empty.
There are locomotives in Belgium. Each can detach and pull a consecutive prefix of the remaining train. No wagon may be left behind or reordered. A segment containing cargo must go to Luxembourg; an empty segment may return to the Netherlands. Empty wagons may also go to Luxembourg.
To keep the Luxembourg-bound trains short, partition the original train into at most nonempty consecutive segments and minimize the largest number of wagons in any Luxembourg-bound segment.
Input
- The first line contains integers , the numbers of wagons, loaded wagons and locomotives.
- The second line contains strictly increasing integers , the indices of loaded wagons.
Output
Print one integer: the length in wagons of the longest Luxembourg-bound train in an optimal partition.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input 1
8 3 3
1 4 7
Output 1
3
Explanation
Use three locomotives for segments [1,3], [4,6], [7,8], of lengths 3, 3 and 2. With a limit of 2, the three loaded wagons must belong to separate trains. Those trains cover at most six wagons and no locomotive remains for the other two.
Input 2
6 4 4
1 2 5 6
Output 2
2
Explanation
Send [1,2] and [5,6] to Luxembourg and [3,4] back to the Netherlands. Three locomotives suffice. A limit of 1 requires four separate loaded trains plus at least one train for the intervening empty wagons, exceeding four locomotives.
Input 3
6 2 2
1 2
Output 3
2
Explanation
The first two wagons are loaded. Send [1,2] to Luxembourg and [3,6] to the Netherlands. A limit of 1 would use both locomotives for the loaded wagons, leaving the four empty wagons behind.