orazma

a.cpp

Apr 27th, 2026
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4.  
  5. using namespace std;
  6. const int INF = 1e9 + 10;
  7. const int MAXN = 1e6 + 10;
  8. int a[MAXN], b[MAXN];
  9. void solve(){
  10.     int n;
  11.     cin >> n;
  12.     for (int i = 1; i <= n; i++){
  13.         cin >> a[i];
  14.     }
  15.     for (int i = 1; i <= n; i++){
  16.         cin >> b[i];
  17.     }
  18.  
  19.     bool was_positive = 0, was_negative = 0;
  20.  
  21.     for (int i = 1; i <= n; i++){
  22.         if (a[i] != b[i]){
  23.             if (b[i] > 0 && was_positive == 0){
  24.                 cout << "NO\n";
  25.                 return;
  26.             }
  27.             if (b[i] < 0 && was_negative == 0){
  28.                 cout << "NO\n";
  29.                 return;
  30.             }
  31.             if (b[i] == 0 && a[i] > 0 && was_negative == 0){
  32.                 cout << "NO\n";
  33.                 return;
  34.             }
  35.             if (b[i] == 0 && a[i] < 0 && was_positive == 0){
  36.                 cout << "NO\n";
  37.                 return;
  38.             }
  39.         }
  40.         if (a[i] > 0){
  41.             was_positive = 1;
  42.         }
  43.         if (a[i] < 0){
  44.             was_negative = 1;
  45.         }
  46.     }
  47.     cout << "YES\n";
  48. }
  49.  
  50. int main()
  51. {
  52.  
  53.     int t = 1;
  54.     cin >> t;
  55.  
  56.     while(t--){
  57.         solve();
  58.     }
  59.  
  60.     return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment