Skip to content

Instantly share code, notes, and snippets.

@lakshith-403
Created April 29, 2021 13:18
Show Gist options
  • Save lakshith-403/d63d105219cc206b73ca1dae5c42f146 to your computer and use it in GitHub Desktop.
Save lakshith-403/d63d105219cc206b73ca1dae5c42f146 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define what_is(a) cout << #a << " is " << a << "\n"
#define checker(a) cout << "checker reached " << a << "\n"
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int solve(){
int n,k;
cin >> n >> k;
int a[n];
for(int i=0;i<n;i++)
cin >> a[i];
int lo[n];
int hi[n];
lo[0] = a[0]+1;
hi[0] = a[0]+1;
for(int i=1;i<n;i++){
int l = a[i]+1;
int h = a[i]+k;
if(hi[i-1]+k-1<l || lo[i-1]-k+1>h)return 0;
lo[i] = max(l,lo[i-1]-k+1);
hi[i] = min(h,hi[i-1]+k-1);
}
if(lo[n-1]==1+a[n-1])return 1;
return 0;
}
signed main(){
io();
int t;
cin >> t;
while(t--){
//solve();
cout << (solve()?"YES\n":"NO\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment