Frog Hops
A frog starts on stone 1 and must reach stone N, jumping to the next stone or skipping one. Jumping from height a to height b costs |a − b|. Minimize the total cost.
Input: the first line has N; the second line has the N stone heights.
Output: the minimum total cost.
Constraints:
- 1 ≤ N ≤ 105
- 0 ≤ hi ≤ 104
Sample Tests
Input 1
4 10 30 40 20
Output 1
30
Input 2
2 10 10
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.