310319: CF1815A. Ian and Array Sorting

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Ian and Array Sortingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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 $a_i$ and $a_{i+1}$ ($1\le i\le 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.

Input

The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — 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\le n\le 3\cdot10^5$) — the number of elements in the array.

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\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 $3\cdot10^5$.

Output

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

ExampleInput
5
3
1 3 2
2
2 1
4
1 3 5 7
4
2 1 4 3
5
5 4 3 2 1
Output
YES
NO
YES
NO
YES
Note

For the first test case, we can increase $a_2$ and $a_3$ both by $1$. The array is now $[1, 4, 3]$.

Then we can decrease $a_1$ and $a_2$ 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, $a_1$ will always be larger than $a_2$. 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.

Input

题意翻译

### 题目描述 为了感谢 $\textrm{lan}$,$\textrm{Mary}$ 赠送了 $\textrm{lan}$ 一个长度为 $n$ 的序列。为了让他自己看起来聪明,他想要让序列按非递减排序。他可以执行以下操作若干次: + 选择数组中的两个元素 $a_i,a_{i+1}$ ( $1\le i<n$ )。 + 同时将它们减去 $1$,或者都加上 $1$。 (注意:操作后 $a_i,a_{i+1}$ 可以是负数或 $0$) 作为一个聪明人,你会注意到,有些序列 $\textrm{lan}$ 无法让其非递减排序。因此,你决定编写一个程序来确定是否可以使数组按非递减顺序排列。 ### 输入格式 第一行是一个正整数 $t$ ( $1\le t\le 10^4$ ),表示测试数据的数量。 对于每组数据: 第一行是一个正整数 $n$ ( $1\le n\le 3\cdot 10^5$ ),表示序列中有多少元素。 第二行是 $n$ 个正整数 $a_1,a_2,\dots,a_n$ ( $1\le a_i\le 10^9$ ),表示序列 $a$ 的元素。 保证 $n$ 的总和不超过 $3\cdot 10^5$。 ### 输出格式 对于每个测试数据,如果该序列在操作后能按非递减顺序排序,输出 `YES`,否则输出 `NO`。 你可以打印 `YES`,`yEs`,`yes`,`Yes`,这些都是可以被接受的。

Output

题目大意:
Ian收到了Mary送的一个长度为n的数组a作为礼物。Ian想要通过有限次以下操作使得数组变为非递减顺序:他选择两个相邻的元素a_i和a_{i+1}(1≤i≤n-1),然后同时增加或减少它们各1。注意,数组的元素可以变为负数。你需要写一个程序来判断是否可能通过这些操作使得数组变为非递减顺序。

输入数据格式:
第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。接下来是每个测试用例的描述。
每个测试用例的第一行包含一个整数n(2≤n≤3×10^5)——数组中元素的数量。
第二行包含n个整数a_1,a_2,…,a_n(1≤a_i≤10^9)——数组a的元素。
保证所有测试用例的n之和不超过3×10^5。

输出数据格式:
对于每个测试用例,如果存在一系列操作使得数组变为非递减顺序,则输出"YES",否则输出"NO"。
输出每个字母的大小写均可。

示例:
输入
```
5
3
1 3 2
2
2 1
4
1 3 5 7
4
2 1 4 3
5
5 4 3 2 1
```
输出
```
YES
NO
YES
NO
YES
```

注意:
在第一个测试用例中,我们可以先将a_2和a_3都增加1,得到数组[1, 4, 3],然后将a_1和a_2都减少1,得到数组[0, 3, 3],此时数组已经为非递减顺序。因此答案是"YES"。
在第二个测试用例中,无论如何操作,a_1总是大于a_2,所以答案是"NO",Ian无法使数组变为非递减顺序。
在第三个测试用例中,数组已经是非递减顺序,所以Ian不需要进行任何操作。题目大意: Ian收到了Mary送的一个长度为n的数组a作为礼物。Ian想要通过有限次以下操作使得数组变为非递减顺序:他选择两个相邻的元素a_i和a_{i+1}(1≤i≤n-1),然后同时增加或减少它们各1。注意,数组的元素可以变为负数。你需要写一个程序来判断是否可能通过这些操作使得数组变为非递减顺序。 输入数据格式: 第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含一个整数n(2≤n≤3×10^5)——数组中元素的数量。 第二行包含n个整数a_1,a_2,…,a_n(1≤a_i≤10^9)——数组a的元素。 保证所有测试用例的n之和不超过3×10^5。 输出数据格式: 对于每个测试用例,如果存在一系列操作使得数组变为非递减顺序,则输出"YES",否则输出"NO"。 输出每个字母的大小写均可。 示例: 输入 ``` 5 3 1 3 2 2 2 1 4 1 3 5 7 4 2 1 4 3 5 5 4 3 2 1 ``` 输出 ``` YES NO YES NO YES ``` 注意: 在第一个测试用例中,我们可以先将a_2和a_3都增加1,得到数组[1, 4, 3],然后将a_1和a_2都减少1,得到数组[0, 3, 3],此时数组已经为非递减顺序。因此答案是"YES"。 在第二个测试用例中,无论如何操作,a_1总是大于a_2,所以答案是"NO",Ian无法使数组变为非递减顺序。 在第三个测试用例中,数组已经是非递减顺序,所以Ian不需要进行任何操作。

加入题单

上一题 下一题 算法标签: