CF1815A.Ian and Array Sorting
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
To thank Ian, Mary gifted an array a of length n to Ian. To make himself look smart, he wants to make the array in non-decreasing order by doing the following finitely many times: he chooses two adjacent elements ai and ai+1 ( 1≤i≤n−1 ), and increases both of them by 1 or decreases both of them by 1 . Note that, the elements of the array can become negative.
As a smart person, you notice that, there are some arrays such that Ian cannot make it become non-decreasing order! Therefore, you decide to write a program to determine if it is possible to make the array in non-decreasing order.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of test cases follows.
The first line of each test case consists of a single integer n ( 2≤n≤3⋅105 ) — the number of elements in the array.
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the elements of the array a .
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105 .
输出格式
For each test case, output "YES" if there exists a sequence of operations which make the array non-decreasing, else output "NO".
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
输入输出样例
输入#1
5 3 1 3 2 2 2 1 4 1 3 5 7 4 2 1 4 3 5 5 4 3 2 1
输出#1
YES NO YES NO YES
说明/提示
For the first test case, we can increase a2 and a3 both by 1 . The array is now [1,4,3] .
Then we can decrease a1 and a2 both by 1 . The array is now [0,3,3] , which is sorted in non-decreasing order. So the answer is "YES".
For the second test case, no matter how Ian perform the operations, a1 will always be larger than a2 . So the answer is "NO" and Ian cannot pretend to be smart.
For the third test case, the array is already in non-decreasing order, so Ian does not need to do anything.