PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000001. Ếch nhảy 1 (Frog 1)
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 1 (Frog 1)
Frog 1
Source: AtCoder
Problem Statement
There are stones in a row, numbered from to . Stone has height .
A frog starts on stone . From stone , it may jump to stone or , provided that the destination exists. A jump from stone to stone costs units of energy.
Determine the minimum total energy needed to reach stone .
Input
The first line contains an integer , the number of stones.
The second line contains integers , the heights in order.
Output
Print one integer: the minimum possible total energy cost.
Subtasks
- Subtask 1 (20 points): ; ().
- Subtask 2 (30 points): ; ().
- Subtask 3 (50 points): ; ().
Examples
Input
4
10 30 40 20
Output
30
Explanation
Jumping along stones costs . No other permitted path has a lower total cost.