#QHD0000002. Ếch 2 (Frog 2)
Ếch 2 (Frog 2)
Frog 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are stones with heights . From stone , the frog may jump to any of . A jump from to costs . Find the minimum cost from stone 1 to stone .
Input
Line 1 contains and . Line 2 contains integers .
Output
Print the minimum total cost.
Subtasks
- Subtask 1 — 20 points: 2 <= N <= 20; 1 <= K <= 5.
- Subtask 2 — 30 points: 2 <= N <= 2000; 1 <= K <= 30.
- Subtask 3 — 50 points: 2 <= N <= 100000; 1 <= K <= 100; 1 <= h_i <= 10000.
Examples
Input
5 3
10 30 40 50 20
Output
30
Explanation
The route costs , and no cheaper route exists.