{
}
Online Python Compiler
Online R Compiler
Online SQL Editor
Online HTML/CSS Editor
Online Java Compiler
Online C Compiler
Online C++ Compiler
Online C# Compiler
Online JavaScript Compiler
Online Typescript Compiler
Typescript Online Compiler
Online GoLang Compiler
Online Rust Compiler
Scala Online Compiler
Dart Online Compiler
Ruby Online Compiler
Online PHP Compiler
Online Swift Compiler
Generating Link
Generating Link
Share your code
Share code
Copy Link
Copied to clipboard
or share using
Black
68
%
Off
November
Stop copy pasting code you don't actually understand
Build the coding confidence you need to become a developer companies will fight for
Stop copy pasting code you don't actually understand
Become a PRO
Become a PRO
Black
68
%
Off
November
Stop copy pasting code you don't actually understand
Build the coding confidence you need to become a developer companies will fight for
Stop copy pasting code you don't actually understand
Become a PRO
Become a PRO
C++ Online Compiler
Learn Python App
Learn Python
main.cpp
Output
main.cpp
Share
Run
Run
// 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
Clear