

実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 点
問題文
個の足場があります。 足場には と番号が振られています。 各 () について、足場 の高さは です。
最初、足場 にカエルがいます。 カエルは次の行動を何回か繰り返し、足場 まで辿り着こうとしています。
- 足場 にいるとき、足場 または へジャンプする。 このとき、ジャンプ先の足場を とすると、コスト を支払う。
カエルが足場 に辿り着くまでに支払うコストの総和の最小値を求めてください。
制約
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
カエルが支払うコストの総和の最小値を出力せよ。
入力例 1Copy
4 10 30 40 20
出力例 1Copy
30
足場 → → と移動すると、コストの総和は となります。
入力例 2Copy
2 10 10
出力例 2Copy
0
足場 → と移動すると、コストの総和は となります。
入力例 3Copy
6 30 10 60 10 60 50
出力例 3Copy
40
足場 → → → と移動すると、コストの総和は となります。
Score : points
Problem Statement
There are stones, numbered . For each (), the height of Stone is .
There is a frog who is initially on Stone . He will repeat the following action some number of times to reach Stone :
- If the frog is currently on Stone , jump to Stone or Stone . Here, a cost of is incurred, where is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible total cost incurred.
Sample Input 1Copy
4 10 30 40 20
Sample Output 1Copy
30
If we follow the path → → , the total cost incurred would be .
Sample Input 2Copy
2 10 10
Sample Output 2Copy
0
If we follow the path → , the total cost incurred would be .
Sample Input 3Copy
6 30 10 60 10 60 50
Sample Output 3Copy
40
If we follow the path → → → , the total cost incurred would be .