A. Single Push
直接乱搞即可。Code
/*
* Author: heyuhhh
* Created Time: 2019/11/16 22:36:20
*/
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << '\n'; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
#define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
int n;
int a[N], b[N], c[N];
void run(){
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) {
cin >> b[i];
c[i] = b[i] - a[i];
}
int cnt = 0;
for(int i = 1; i <= n; i++) {
if(c[i] < 0) return pt("NO");
}
int l = 1, r = n;
while(l <= r && c[l] == 0) ++l;
while(l <= r && c[r] == 0) --r;
int ok = 1;
for(int i = l + 1; i <= r; i++) if(c[i] != c[i - 1]) ok = 0;
if(l > r || ok) return pt("YES");
else return pt("NO");
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T;
while(T--) run();
return 0;
}