#P7625. [COCI 2011/2012 #1] JABUKE
[COCI 2011/2012 #1] JABUKE
Description
Mirko has recently become obsessed with a video game.
The game screen is divided into columns. At the bottom of the screen, there is a ship that is columns wide. In the game, the player can move the ship left and right, but the ship must always stay completely inside the screen. Initially, the ship occupies the leftmost columns of the screen.
Apples will fall from the top of the screen. Each apple starts falling straight down from one of the columns at the top. When the current apple reaches the bottom of the screen, the next apple starts falling.
If, when an apple reaches the bottom, the ship covers the column where the apple is, we say the apple is picked up. Your task is to minimize the distance the ship moves, while picking up all the apples.
Input Format
The first line contains two integers separated by spaces.
The second line contains an integer , indicating the number of apples that will fall.
The next lines: the -th line contains one integer, indicating from which column the -th apple will start falling.
Output Format
Output one integer on a single line, the minimum distance the ship needs to move.
5 1
3
1
5
3
6
5 2
3
1
5
3
4
Hint
Constraints
For of the testdata, , .
Explanation
The score for this problem follows the original COCI settings, with a full score of .
Translated from COCI2011-2012 CONTEST #1 T1 JABUKE.
Translated by ChatGPT 5
京公网安备 11011102002149号