当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7246:Wavy Tree

题目描述
An array $a$ of length $n$ is said to be wavy, if for each $1 < i < n$ either $a_i > \max \{a_{i-1},a_{i+1}\}$ or $a_i < \min \{a_{i-1},a_{i+1}\}$ holds.

You are given an array $b$ of length $n$ $(1\leq b_i\leq 10^9)$ , consisting of integers. You want to make the array wavy. To do that you can spend some coins, with each coin you can make one element in $b$ increase or decrease by $1$. Calculate the minimum number of coins you need to spend to make the array wavy.
输入解释
The first line contains the number of test cases $T$ $(1\le T\le 10^3)$.

The first line of each test case contains one integer $n$ $(1\leq n\leq 10^6)$ - the length of array $b$ .

The second line contains $n$ integers $b_1,b_2,\cdots,b_n$ $(1\leq b_i\leq 10^9)$ - the array $b$ .

It's guarantee that the sum of $n$ among all test cases is not greater than $3\times 10^6$ .
输出解释
For each test case, output one integer, the minimum number of coins you need to spend to make the array wavy.

输入样例
3
4
1 7 6 5
6
1 2 3 4 5 6
6
1 1 4 5 1 4
输出样例
2
4
4

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7246

最后修改于 2022-09-15T06:17:36+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 524288/524288K(Java/Others)