Problems > Frog Hops

Frog Hops

Difficulty: 1200 3000 ms 128 MB

dp

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.