-
Notifications
You must be signed in to change notification settings - Fork 3
/
B_Array_Decrements.cpp
116 lines (85 loc) · 2.27 KB
/
B_Array_Decrements.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma")
#include<bits/stdc++.h>
//ordered set
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
// Header Files End
using namespace std;
using namespace __gnu_pbds;
//typedef tree<pair<int, int>, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order --> find the element at the ith index
// order_of_key --> find the element smaller than the parameter passed in the array
//if you want to arrange the values in descending order replace less<int> with greater<int>
//less_equal for multiple values
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
//ordered_set<pair<int, int>> A; , ordered<int> A;
template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#define int long long
double pi = 3.14159265358979323846;
#define PB push_back
#define MP make_pair
#define INF 1000000007
const int mod = 1e9 + 7;
//vector<int> graph[(int)1000]; //defining array of vectors
//to_ullong()
int case_ans = 1;
//cout << "Case #" << case_ans << ": " << ans << endl;
void solve() {
int n;
cin >> n;
int a[n], b[n];
for (auto &it : a) {
cin >> it;
}
for (auto &it : b) {
cin >> it;
}
int maxi = a[0] - b[0];
//cout << mini << endl;
for (int i = 1; i < n; i++) {
maxi = max(maxi, a[i] - b[i]);
}
if (maxi < 0) {
cout << "NO" << endl;
return;
}
//a[0] = a[0] - maxi;
for (int i = 0; i < n; i++) {
a[i] = max(0ll, a[i] - maxi);
}
bool flag = true;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
flag = false;
break;
}
}
if (flag) {
cout << "YES" << endl;
//return;
}
else {
//cout << "H" << endl;
cout << "NO" << endl;
}
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("ccallinput.txt", "r", stdin);
freopen("ccalloutput.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}