CF2134C Even Larger
Description
An array is called good if, for every subarray$$$^{\\text{∗}}$$$ of length at least $$$2$$$, the sum of the elements at even indices (with respect to the original array) is greater than or equal to the sum of the elements at odd indices. Array indexing starts from $$$1$$$.
For example, the arrays $$$\[3,8,4,4\]$$$ and $$$\[2,3,1,4,2\]$$$ are good. The array $$$\[0,2,4,1\]$$$ is not because, in the subarray $$$\[2,4,1\]$$$, the elements at even indices in the original array are $$$2$$$ (index $$$2$$$) and $$$1$$$ (index $$$4$$$), while the only element at an odd index is $$$4$$$ (index $$$3$$$). Since $$$2 + 1 < 4$$$, the condition does not hold for this subarray.
You are given an array of $$$n$$$ non-negative integers $$$a\_1,a\_2,\\ldots,a\_n$$$. In one operation, you can decrease any element in the array by $$$1$$$, but all elements must remain non-negative. Your task is to find the minimum number of operations needed to make the array $$$a$$$ good. It can be proved that it is possible to make the array good using a finite number of operations.
$$$^{\\text{∗}}$$$An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Input Format
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$) — the length of the array $$$a$$$.
The second line of each test case contains $$$n$$$ non-negative integers $$$a\_1,a\_2,\\ldots,a\_n$$$ ($$$0 \\le a\_i \\le 10^9$$$) — the elements of the array $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.
Output Format
For each test case, output a single integer in a new line — the minimum number of operations needed to make the array $$$a$$$ good.
Explanation/Hint
In the first test case, the array $$$a$$$ is already good, so the answer is $$$0$$$. Below are the checks for each subarray:
SubarrayEven Index SumOdd Index SumCondition met?$$$\[3,8\]$$$$$$8$$$$$$3$$$Yes$$$\[8,4\]$$$$$$8$$$$$$4$$$Yes$$$\[4,4\]$$$$$$4$$$$$$4$$$Yes$$$\[3,8,4\]$$$$$$8$$$$$$3+4=7$$$Yes$$$\[8,4,4\]$$$$$$8+4 = 12$$$$$$4$$$Yes$$$\[3,8,4,4\]$$$$$$8+4=12$$$$$$3 + 4 = 7$$$YesIn the second test case, the array $$$a$$$ is not good:
SubarrayEven Index SumOdd Index SumCondition met?$$$\[0,2\]$$$$$$2$$$$$$0$$$Yes$$$\[2,3\]$$$$$$2$$$$$$3$$$No$$$\[3,5\]$$$$$$5$$$$$$3$$$Yes$$$\[0,2,3\]$$$$$$2$$$$$$0+3=3$$$No$$$\[2,3,5\]$$$$$$2 + 5 = 7$$$$$$3$$$Yes$$$\[0,2,3,5\]$$$$$$2+5 = 7$$$$$$0+3 = 3$$$YesHowever, if we perform an operation on index $$$3$$$, the array becomes $$$\[0,2,2,5\]$$$ and is good now:
SubarrayEven Index SumOdd Index SumCondition met?$$$\[0,2\]$$$$$$2$$$$$$0$$$Yes$$$\[2,2\]$$$$$$2$$$$$$2$$$Yes$$$\[2,5\]$$$$$$5$$$$$$2$$$Yes$$$\[0,2,2\]$$$$$$2$$$$$$0+2=2$$$Yes$$$\[2,2,5\]$$$$$$2 + 5 = 7$$$$$$2$$$Yes$$$\[0,2,2,5\]$$$$$$2+5 = 7$$$$$$0+2 = 2$$$YesTherefore, the answer is $$$1$$$.