Problem AJ
Freight Train

The chemical company NS (Nasty Substances) has three factories: one in the Netherlands, one in Belgium and one in Luxembourg. Chemicals are moved between the factories on a regular basis, which is always done by freight train. Last night, the the weekly shipment of chemicals was again sent from the factory in the Netherlands to the factory in Belgium. However, something has gone wrong: some of the chemicals that arrived in Belgium were supposed to go to the factory in Luxembourg. What’s more, the Luxumbourg chapter is eagerly awaiting the arrival of its chemicals, as any delay in delivery causes major issues in the production pipeline.
In order to make sure that the error can be corrected as
quickly as possible, an additional
Input
The input starts with a line containing an integer
-
One line with three space-separated integers
, and , satisfying and and . These denote the number of wagons of the freight train stationed in Belgium, the number of wagons still containing freight and the number of locomotives. -
One line with
space-separated integers, denoting the numbers of the wagons that still contain freight in ascending order. Wagons are numbered through .
Output
For each test case, output one line with a single integer, denoting the number of wagons of the longest train heading for Luxembourg.
In the first test case, you take the first two wagons and send them towards Luxembourg. The remaining wagons can go back to the Netherlands.
In the second test case, your best option is to simply split the train in three parts, each of which heads for Luxembourg.
In the third test case, split the train into three parts of two wagons each. Two of those are sent towards Luxembourg. Note that one of the locomotives remains unused.
Sample Input 1 | Sample Output 1 |
---|---|
3 6 2 2 1 2 8 3 3 1 4 7 6 4 4 1 2 5 6 |
2 3 2 |