CF2060D.Subtract Min Sort

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Subtract Min Sort

You are given a sequence aa consisting of nn positive integers.

You can perform the following operation any number of times.

  • Select an index ii (1i<n1 \le i \lt n), and subtract min(ai,ai+1)\min(a_i,a_{i+1}) from both aia_i and ai+1a_{i+1}.

Determine if it is possible to make the sequence non-decreasing by using the operation any number of times.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (2n21052 \le n \le 2 \cdot 10^5).

The second line of each test case contains a1,a2,,ana_1,a_2,\ldots,a_n (1ai1091 \le a_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

If 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.

Note

In 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=1i=1, the array becomes [0,1,2,3][0,1,2,3], which is now in nondecreasing order.

Samples

5
5
1 2 3 4 5
4
4 3 2 1
4
4 5 2 3
8
4 5 4 5 4 5 4 5
9
9 9 8 2 4 4 3 5 3
YES
NO
YES
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验