Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define all(x) x.begin(), x.end()
- #define small_black_cock cout
- using namespace std;
- using ll = long long;
- int main() {
- int t;
- cin >> t;
- for(int k = 0; k < t; k++){
- int n ;
- cin >> n;
- vector<int> a(n), b(n), d(n);
- for(int i = 0; i < n; i++) cin >> a[i];
- for(int i = 0; i < n; i++) cin >> b[i];
- bool flag = false;
- int nozero = -1, zero = -1;
- for(int i =0; i < n; i++){
- if(b[i] == 0){
- d[i] = a[i];
- if(nozero != -1){
- if(d[i] > d[nozero]){
- flag = true;
- break;
- }
- }
- zero = i;
- }else{
- d[i] = a[i] - b[i];
- if(d[i] < 0){
- flag = true;
- break;
- }
- if(zero != -1){
- if(d[zero] > d[i]){
- flag = true;
- break;
- }
- zero = -1;
- }
- if(nozero != -1){
- if(d[nozero] > d[i]){
- flag = true;
- break;
- }
- }
- nozero = i;
- // cout << nozeroID << " ";
- }
- }
- if(!flag){
- cout<< "YES" << "\n";
- }else{
- cout << "NO" << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment