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

#BS0000318. Chia đoàn tàu hàng (Freight Train)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 NN wagons numbered 11 through NN in order. Exactly WW wagons carry cargo for Luxembourg; all others are empty.

There are LL 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 LL nonempty consecutive segments and minimize the largest number of wagons in any Luxembourg-bound segment.

Input

  • The first line contains integers N,W,LN,W,L, the numbers of wagons, loaded wagons and locomotives.
  • The second line contains WW strictly increasing integers p1,…,pWp_1,\ldots,p_W, 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): 1≤N≤201\le N\le20; 1≤W≤N1\le W\le N; 1≤L≤201\le L\le20; 1≤p1<⋯<pW≤N1\le p_1<\cdots<p_W\le N.
  • Subtask 2 (30 points): 1≤N≤1091\le N\le10^9; 1≤W,L≤1041\le W,L\le10^4; W≤NW\le N; 1≤p1<⋯<pW≤N1\le p_1<\cdots<p_W\le N; L=1L=1.
  • Subtask 3 (50 points): 1≤N≤1091\le N\le10^9; 1≤W,L≤1041\le W,L\le10^4; W≤NW\le N; 1≤p1<⋯<pW≤N1\le p_1<\cdots<p_W\le N.

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.