{}
run-icon
main.cpp
// PASTING COPIED CODE TO HELP DEBUG FOR TESTING PURPOSES ONLY. // OWNER: https://codeforces.com/profile/sensei_nitb #include<bits/stdc++.h> using namespace std; #define ll long long #define all(v) v.begin(),v.end() int binary_search(vector<ll>& b, ll target) { int m = b.size(); int low=0; int high=m-1; int res = -1; while(low<=high){ int mid=(low+high)/2; ll val=b[mid]; if(val >= target){ res = mid; high=mid-1; } else { low=mid+1; } } return res; } int main(){ ll t; cin >> t; while(t--) { ll n,m; cin >> n>>m; vector<ll> a(n); for(int i = 0; i < n; i++) cin >> a[i]; vector<ll> b(m); for(int i = 0; i < m; i++) cin >> b[i]; sort(all(b)); int bs = binary_search(b, -1e18+a[0]); if(bs != -1) { a[0] = min(a[0], b[bs] - a[0]); } bool flag=true; for(int i=1;i<n;i++){ vector<int> opts; bs = binary_search(b, a[i-1] + a[i]); if(a[i] >= a[i-1]) opts.push_back(a[i]); if(bs != -1) opts.push_back(b[bs] - a[i]); if(opts.empty()) { flag = false; break; } int mi = *min_element(all(opts)); if(mi >= a[i - 1]) { a[i] = mi; } } if(flag)cout<<"YES"; else cout<<"NO"; cout<<endl; } }
Output