atcoder#ARC101A. [ABC107C] Candles
[ABC107C] Candles
Score : points
Problem Statement
There are candles placed on a number line. The -th candle from the left is placed on coordinate . Here, holds.
Initially, no candles are burning. Snuke decides to light of the candles.
Now, he is at coordinate . He can move left and right along the line with speed . He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light candles.
Constraints
- is an integer.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum time required to light candles.
5 3
-30 -10 10 20 50
40
He should move and light candles as follows:
- Move from coordinate to .
- Light the second candle from the left.
- Move from coordinate to .
- Light the third candle from the left.
- Move from coordinate to .
- Light the fourth candle from the left.
3 2
10 20 30
20
1 1
0
0
- There may be a candle placed at coordinate .
8 5
-9 -7 -4 -3 1 2 3 4
10