Freight Train

Time limit2sMemory limit256 MB

Summary
Partition the train into at most L consecutive groups covering every loaded wagon with a Luxembourg-bound group while minimizing the longest such group.
Level

Medium6 of 10

Topics
Binary search, Greedy
Solved
No attempts yet

Problem

The chemical company NS runs three factories: one in the Netherlands, one in Belgium, and one in Luxembourg. All goods between the factories travel by freight train. Last night the weekly load left the Dutch factory for the Belgian factory, and it was loaded wrong. Some of the wagons that arrived in Belgium carry chemicals meant for the Luxembourg factory. That factory is waiting for them, and its production line stops for as long as the delivery is late.

To fix the mistake quickly, L−1L-1 more locomotives were sent to the freight train standing at the Belgian factory, so LL locomotives are available in total. One locomotive can take an initial segment of the train, that is, the first KK wagons, and haul it either back to the Netherlands or on to Luxembourg. There is no time for any other rearrangement. A shorter train runs faster, so the trains going to Luxembourg have to be as short as possible. Trains going back to the Netherlands may be any length.

You are given the list of wagons that have to reach Luxembourg. Every other wagon is empty and may either travel on to Luxembourg or return to the Netherlands. No wagon can be left behind in Belgium. Split the freight train into at most LL consecutive trains so that the longest train heading for Luxembourg is as short as possible.

Input

The first line contains an integer TT, the number of test cases. Each test case is given as follows.

  • One line with three space separated integers NN, WW, and LL (1≤N≤1091 \le N \le 10^9, 1≤W,L≤1041 \le W, L \le 10^4, W≤NW \le N). NN is the number of wagons of the freight train standing in Belgium, WW is the number of wagons that still carry freight, and LL is the number of locomotives.
  • One line with WW space separated integers in ascending order, the numbers of the wagons that still carry freight. The wagons are numbered 11, 22, and so on up to NN, starting at the front of the train.

Output

For each test case, print one line with a single integer, the number of wagons of the longest train heading for Luxembourg.

Hint

In the first case of the sample input, take the first two wagons and send them to Luxembourg. The rest of the train goes back to the Netherlands.

In the second case, the best option is to cut the train into three parts and send all three to Luxembourg.

In the third case, cut the train into three parts of two wagons each and send two of them to Luxembourg. One locomotive stays unused.

Examples1

  1. Example 1

    Input
    3
    6 2 2
    1 2
    8 3 3
    1 4 7
    6 4 4
    1 2 5 6
    
    Expected output
    2
    3
    2