题库练习 Helping the Nature
← 上一题 下一题 →

A15237 | Helping the Nature

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees.

There are $n$ trees growing near the path, the current levels of moisture of each tree are denoted by the array $a_1, a_2, \dots, a_n$ . Leon has learned three abilities which will help him to dry and water the soil.

- Choose a position $i$ and decrease the level of moisture of the trees $1, 2, \dots, i$ by $1$ .
- Choose a position $i$ and decrease the level of moisture of the trees $i, i + 1, \dots, n$ by $1$ .
- Increase the level of moisture of all trees by $1$ .

Leon wants to know the minimum number of actions he needs to perform to make the moisture of each tree equal to $0$ .

输入格式

The first line contains a single integer $t$ ( $1 \le t \le 2 \cdot 10^4$ ) — the number of test cases. The description of $t$ test cases follows.

The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 200\,000$ ).

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^9 \leq a_i \leq 10^9$ ) — the initial levels of trees moisture.

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $200\,000$ .

输出格式

For each test case output a single integer — the minimum number of actions. It can be shown that the answer exists.

输入输出样例

输入 #1
4
3
-2 -2 -2
3
10 4 7
4
4 -4 4 -4
5
1 -2 3 -4 5
输出 #1
2
13
36
33
C++ 编辑器
输入
输出