PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000002. Ếch nhảy 2 (Frog 2)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ếch nhảy 2 (Frog 2)
Frog 2
Source: AtCoder
Problem Statement
There are stones in a row, numbered from to , with heights .
A frog starts on stone . From stone , it may jump to any stone such that and . Such a jump costs .
Find the minimum total cost required to reach stone .
Input
The first line contains and : the number of stones and the maximum number of positions advanced by a single jump.
The second line contains integers , the stone heights.
Output
Print one integer: the minimum total cost of all jumps.
Subtasks
- Subtask 1 (20 points): ; ; ().
- Subtask 2 (30 points): ; ; ().
- Subtask 3 (50 points): ; ; ().
Examples
Input
5 3
10 30 40 50 20
Output
30
Explanation
Choose jumps ; the second jump spans indices, allowed by . Total cost: .