当前位置: 首页> 汽车> 报价 > 网络维护工作_整站网站优化价格_360收录_企点客服

网络维护工作_整站网站优化价格_360收录_企点客服

时间:2025/8/23 12:56:40来源:https://blog.csdn.net/2303_79062963/article/details/143455500 浏览次数: 0次
网络维护工作_整站网站优化价格_360收录_企点客服

D. Ian and Array Sorting

To thank Ian, Mary gifted an array a a a of length n n 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 a_i ai and a i + 1 a_{i+1} ai+1 ( 1 ≤ i ≤ n − 1 1\le i\le n-1 1in1), and increases both of them by 1 1 1 or decreases both of them by 1 1 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 t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1t104) — the number of test cases. The description of test cases follows.

The first line of each test case consists of a single integer n n n ( 2 ≤ n ≤ 3 ⋅ 1 0 5 2\le n\le 3\cdot10^5 2n3105) — the number of elements in the array.

The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1,a_2,\ldots,a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 1\le a_i\le 10^9 1ai109) — the elements of the array a a a.

It is guaranteed that the sum of n n n over all test cases does not exceed 3 ⋅ 1 0 5 3\cdot10^5 3105.

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

Example

Input

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 a_2 a2 and a 3 a_3 a3 both by 1 1 1. The array is now [ 1 , 4 , 3 ] [1, 4, 3] [1,4,3].

Then we can decrease a 1 a_1 a1 and a 2 a_2 a2 both by 1 1 1. The array is now [ 0 , 3 , 3 ] [0, 3, 3] [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 a_1 a1 will always be larger than a 2 a_2 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.

code

#include<bits/stdc++.h>
#define int long long
#define endl '\n'using namespace std;const int N = 2e5+10,INF=0x3f3f3f3f,mod=1e9+7;typedef pair<int,int> PII;int T=1;void solve(){int n;cin>>n;vector<int> a(n+5,0);for(int i=0;i<n;i++) cin>>a[i];int sum=0; for(int i=0;i<n;i++){if(i%2) sum+=a[i];else sum-=a[i];}if(n&1 || sum>=0) cout<<"YES"<<endl;else cout<<"NO"<<endl;
}signed main(){cin>>T; while(T--){solve();}return 0;
}
关键字:网络维护工作_整站网站优化价格_360收录_企点客服

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: