思路解析:
当数组的长度为偶数时,很显然k直接等于n总能将数组变成非降序。
要变成非降序应使选择的区间尽可能大,操作的次数尽可能多
当数组的长度为奇数时,将每个数都加至它的极限值,最后判断一下是否为非降序即可。
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define int long long
using T = pair<int, int>;
//set<int>S;
//unordered_map<int, int>mp;
const int N = 1e5 + 10;
int a[N];
int op[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
int n; cin >> n;
int i;
for (i = 1; i <= n; ++i) {
cin >> a[i];
}
int cnt{};
if (!(n & 1)) {
cout << "YES" << endl;
}
else {
for (i = n - 1; i >= 2; i -= 2) {
cnt += max(0ll, (a[i+1] - (a[i]+i*cnt))/i);
a[i] += cnt * i;
a[i - 1] += cnt * (i - 1);
}
for (i = 2; i <= n; ++i) {
if (a[i] < a[i - 1]) {
cout << "NO" << endl;
break;
}
}
if (i > n) {
cout << "YES" << endl;
}
}
}
return 0;
}