-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
31 lines (30 loc) · 765 Bytes
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n, k;
cin >> n >> k;
vector <int> a (n);
vector <int> ord (n);
for(int i = 0; i < n; i++) {
cin >> a[i];
ord[i] = i;
}
sort(ord.begin(), ord.end(), [&] (int i, int j) { return a[i] > a[j]; } );
vector <int> h (n, 0);
for(int x = 0; x < n; x++) {
int i = ord[x];
int opt = a[i];
if(i > 0) opt = max(opt, h[i - 1] - k + 1);
if(i < n - 1) opt = max(opt, h[i + 1] - k + 1);
h[i] = opt;
}
bool bad = (h[0] != a[0]) || (h[n - 1] != a[n - 1]);
for(int i = 0; i < n; i++) bad |= (h[i] - a[i]) >= k;
if(bad) cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}