

実行時間制限: 2 sec / メモリ制限: 256 MB
配点 : 点
問題文
個のマスが左右に一列に並んでいます. これらのマスには,左のマスから順に の番号が付けられています.
あなたは,最初マス にいます. 隣り合うマスの間は自由に移動することができ,マス またはマス にたどり着くとゴールすることができます. ただし, について,マス には料金所があり,そのためマス に移動してくる際には のコストがかかります. なお,マス ,マス ,マス には料金所がないことが保証されます.
ゴールするまでにかかるコストの最小値を求めてください.
制約
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
ゴールするまでにかかるコストの最小値を出力せよ.
入力例 1Copy
5 3 3 1 2 4
出力例 1Copy
1
次のようにするのが最適です.
- まず,マス から,マス へ移動する.このとき,マス には料金所があるので,コスト がかかる.
- 次に,マス から,マス へ移動する.このときはコストはかからない.
- マス に到着したので,ゴールする.
このようにすると,コストは合計で になります.
入力例 2Copy
7 3 2 4 5 6
出力例 2Copy
0
まったくコストがかからないこともあります.
入力例 3Copy
10 7 5 1 2 3 4 6 8 9
出力例 3Copy
3
Score : points
Problem Statement
There are squares arranged in a row, numbered from left to right.
Initially, you are in Square . You can freely travel between adjacent squares. Your goal is to reach Square or Square . However, for each , there is a toll gate in Square , and traveling to Square incurs a cost of . It is guaranteed that there is no toll gate in Square , Square and Square .
Find the minimum cost incurred before reaching the goal.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum cost incurred before reaching the goal.
Sample Input 1Copy
5 3 3 1 2 4
Sample Output 1Copy
1
The optimal solution is as follows:
- First, travel from Square to Square . Here, there is a toll gate in Square , so the cost of is incurred.
- Then, travel from Square to Square . This time, no cost is incurred.
- Now, we are in Square and we have reached the goal.
In this case, the total cost incurred is .
Sample Input 2Copy
7 3 2 4 5 6
Sample Output 2Copy
0
We may be able to reach the goal at no cost.
Sample Input 3Copy
10 7 5 1 2 3 4 6 8 9
Sample Output 3Copy
3