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 ~. The height of the ~ i ~-th stone is ~ h_i ~.
A frog starts on stone ~ 1 ~. It can jump to any of the next ~ K ~ stones (~ i+1~ to ~ i+K ~), with a cost of ~ |h_i - h_j| ~, where ~ j ~ is the stone it wants to jump to.
Find the minimum cost for the frog to reach stone ~N ~.
Input
- The first line contains two integers ~N ~ and ~ K~ (~ 2 \leq N \leq 10^5 ~, ~ 1 \leq K \leq 100 ~).
- The second line contains ~ N ~ integers ~ h_1, h_2, ..., h_N ~ (~ 1 \leq h_i \leq 10^5 ~).
Output
- Print the minimum cost required.
Sample Input
5 3
10 30 40 50 20
Sample Output
30
Notes
- Con ếch sẽ nhảy như sau: ~1→2→5~,
Bình luận