Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
There are ~N~ stones numbered ~1,2,3,...,N~. For each ~i~ (~1 \leq i \leq N~), the height of the ~i~-th stone is ~h_i~.
~Jack~ having skills like frogs stands on stone ~1~. He can repeatedly perform the following action any number of times until he reaches stone ~N~:
- If ~Jack~ is on stone ~i~, he can jump to stone ~i+1~ or ~i+2~ with a cost of ~|h_i - h_j|~, where ~j~ is the position he wants to jump to.
Find the minimum cost for ~Jack~ to reach stone ~N~.
Input
- The first line contains the integer ~N~ (~ 2 \leq N \leq 10^5~).
- The second line contains ~N~ integers: ~h_1, h_2, ..., h_N~ with ~1 \leq h_i \leq 10^5~.
Output
- Print the minimum cost required.
Sample Input
4
10 30 40 20
Sample Output
30
Notes
- ~Jack~ will jump as follows: ~1~ to ~2~ to ~4~.
Bình luận