Mirko has recently discovered an old video game. The screen of this game is divided into
Apples are being dropped from the top of the screen. Each apple starts its fall at the top of one of the
An apple is said to be picked up if the boat is placed so that it occupies the column down which the apple is falling when it reaches the bottom. The goal of the game is to pick up all of the apples, in a way that minimizes the distance that the boat must travel.
Input Specification
The first line of input contains two space separated integers
The second line of input contains an integer
The following
Output Specification
The only line of output must contain the minimal distance that the boat must travel in order to pick up all the apples.
Sample Input 1
5 1
3
1
5
3
Sample Output 1
6
Sample Input 2
5 2
3
1
5
3
Sample Output 2
4
Comments
I think example case number 2 is wrong if calculated mathematicallly. The boat starts with length 2 so the first apple will fall right in. The second apple is at 5, so the boat needs to travel 3 units to get it. The 3rd apple is at 3, where the other end of the boat is, so the answer i think is 3. Please tell me if i am wrong or not.
When the boat collects the second apple, the boat occupies columns 4 and 5. The boat must move left 1 column to collect the third apple.
thank you