A6917. 跳石阶
编程题
普及-
知识点
题目描述
小青蛙准备从第 $1$ 块石阶跳到第 $n$ 块。第 $i$ 块石阶的高度是 $h_i$。
每次它可以从当前石阶跳到下一块($i \to i+1$)或隔一块($i \to i+2$)。
一次跳跃的体力消耗等于两块石阶高度差的绝对值:$\lvert h_x - h_y \rvert$。
请你计算:从第 $1$ 块跳到第 $n$ 块的最小总消耗。
每次它可以从当前石阶跳到下一块($i \to i+1$)或隔一块($i \to i+2$)。
一次跳跃的体力消耗等于两块石阶高度差的绝对值:$\lvert h_x - h_y \rvert$。
请你计算:从第 $1$ 块跳到第 $n$ 块的最小总消耗。
输入格式
第一行:一个整数 $n$。
第二行:$n$ 个整数,依次为 $h_1, h_2, \dots, h_n$。
第二行:$n$ 个整数,依次为 $h_1, h_2, \dots, h_n$。
输出格式
一行,一个整数,表示最小总消耗。
输入输出样例
输入 #1
6 30 10 60 10 60 50
输出 #1
40
说明/提示
- $1 \le n \le 100000$
- $0 \le h_i \le 10^9$
对于样例:
一种最优方案:$1 \to 3 \to 5 \to 6$
消耗为 $\lvert 30-60\rvert + \lvert 60-60\rvert + \lvert 60-50\rvert = 30+0+10=40$。
- $0 \le h_i \le 10^9$
对于样例:
一种最优方案:$1 \to 3 \to 5 \to 6$
消耗为 $\lvert 30-60\rvert + \lvert 60-60\rvert + \lvert 60-50\rvert = 30+0+10=40$。