Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <tuple>
  4. #include <set>
  5. #include <map>
  6. #include <cmath>
  7. #include <string>
  8. #include <algorithm>
  9. #define int long long
  10. #define all(x) (x).begin(), (x).end()
  11. #define allr(x) (x).rbegin(), (x).rend()
  12.  
  13. using namespace std;
  14.  
  15. const int MOD = 1e9 + 7;
  16. const int INF = 1e9;
  17.  
  18. int gcd(int a, int b)
  19. {
  20.     return (a == 0 ? b : gcd(b % a, a));
  21. }
  22.  
  23. signed main()
  24. {
  25.     int q;
  26.     cin >> q;
  27.     while(q--)
  28.     {
  29.         int n;
  30.         cin >> n;
  31.         vector <int> a(n), b(n);
  32.         for (int i = 0; i < n; ++i)
  33.             cin >> a[i];
  34.         for (int i = 0; i < n; ++i)
  35.             cin >> b[i];
  36.  
  37.         if (a[0] != b[0])
  38.             cout << "NO\n";
  39.         else
  40.         {
  41.             bool gotUp = 0, gotDown = 0, got1 = 0, gotm1 = 0, imp = 0;
  42.             for (int i = 0; i < n; ++i)
  43.             {
  44.                 if (a[i] < b[i])
  45.                     gotUp = 1;
  46.                 if (a[i] > b[i])
  47.                     gotDown = 1;
  48.                 if ((!got1 && gotUp) || (!gotm1 && gotDown))
  49.                 {
  50.                     imp = 1;
  51.                     break;
  52.                 }
  53.                 if (a[i] == 1)
  54.                     got1 = 1;
  55.                 if (a[i] == -1)
  56.                     gotm1 = 1;
  57.             }
  58.  
  59.             if (imp)
  60.                 cout << "NO\n";
  61.             else
  62.                 cout << "YES\n";
  63.         }
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement