← 返回 bytedance 的题目列表Minimum Cost to Reach Last Index (1 or 2 steps)
类型:online_judge
Given an array cost where cost[i] is the cost of stepping on index i. You start at index 0 and can move either 1 or 2 steps each time, aiming to reach index n-1.
Compute the minimum total cost to reach n-1. Rules:
You must pay cost[0] to start at index 0.
Every time you land on index i, you pay cost[i].
Input:
First line integer n
Second line n integers cost
Output: one integer, the minimum total cost.
Constraints:
1 <= n <= 2 * 10^5
0 <= cost[i] <= 10^9
Example: Input:
5
1 100 1 1 1
Output:
4
Example
Input
5
1 100 1 1 1
Output
4