fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
  5. #define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; i--)
  6. #define pb push_back
  7. #define ll long long
  8. #define MASK(i) (1LL << (i))
  9.  
  10. const int MAXN = (int)2e5 + 5;
  11.  
  12. ll t, n, a[MAXN], b[MAXN], pointer;
  13.  
  14. void solve(){
  15. FOR(i, 1, n - 1){
  16. a[i + 1] += (a[i] / 2);
  17. a[i] %= 2;
  18. b[i + 1] += (b[i] / 2);
  19. b[i] %= 2;
  20. }
  21. FORD(i, n, 1){
  22. if(b[i] > a[i]){
  23. cout << "NO\n";
  24. return;
  25. }
  26. else if(b[i] < a[i]){
  27. cout << "YES\n";
  28. return;
  29. }
  30. }
  31. cout << "YES\n";
  32. }
  33. int main() {
  34. ios_base::sync_with_stdio(0);
  35. cin.tie(0); cout.tie(0);
  36. cin >> t;
  37. while(t--){
  38. cin >> n;
  39. FOR(i, 1, n) cin >> a[i];
  40. FOR(i, 1, n) cin >> b[i];
  41. solve();
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 5280KB
stdin
4
4
1 1 4 5
3 1 2 3
2
1 0
0 1
3
1 1 1
1 1 1
1
1
100
stdout
YES
NO
YES
NO