A delivery drone must cross
The drone starts at tower
The energy cost of jumping from tower
The hidden idea: the best cost to reach a tower depends only on the best costs of the previous one or two towers.
The first line contains an integer KaTeX can only parse string typed expression.
The second line contains KaTeX can only parse string typed expression integers KaTeX can only parse string typed expression.
Print a single integer — the minimum total energy required to reach tower KaTeX can only parse string typed expression.
Input
4
10 30 40 20Output30ExplanationOne optimal path is tower KaTeX can only parse string typed expression, costing KaTeX can only parse string typed expression.
Example 2:
Input
2
7 4Output3