Problem D

Statement
Copy Copied
D. Subtract Min Sorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence $$$a$$$ consisting of $$$n$$$ positive integers.You can perform the following operation any number of times.  Select an index $$$i$$$ ($$$1 \le i < n$$$), and subtract $$$\min(a_i,a_{i+1})$$$ from both $$$a_i$$$ and $$$a_{i+1}$$$. Determine if it is possible to make the sequence non-decreasing by using the operation any number of times.InputEach 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 second line of each test case contains $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$).It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.OutputIf it is possible to make the sequence non-decreasing, print "YES" on a new line. Otherwise, print "NO" on a new line.You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses.ExampleInput551 2 3 4 544 3 2 144 5 2 384 5 4 5 4 5 4 599 9 8 2 4 4 3 5 3OutputYES
NO
YES
YES
NO
NoteIn the first test case, the array is already sorted.In the second test case, we can show that it is impossible.In the third test case, after performing an operation on $$$i=1$$$, the array becomes $$$[0,1,2,3]$$$, which is now in nondecreasing order.