fork download
  1. #include <iostream>
  2. #include<string>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. void check(vector<int> a, vector<int> b, int n)
  8. {
  9. bool met_plus = false, met_minus = false;
  10. bool possible = true;
  11. for (int i = 0; i < n && possible; i++)
  12. {
  13. if (a[i] > b[i])
  14. {
  15. if (!met_minus)
  16. possible = false;
  17. }
  18. else if (a[i] < b[i])
  19. {
  20. if (!met_plus)
  21. possible = false;
  22. }
  23. if (a[i] == -1)
  24. met_minus = true;
  25. if (a[i] == 1)
  26. met_plus = true;
  27. }
  28. possible ? cout << "YES\n" : cout << "NO\n";
  29. }
  30.  
  31. int main() {
  32. int t;
  33. cin >> t;
  34. for (int i = 0; i < t; i++)
  35. {
  36. int n;
  37. vector<int> a, b;
  38. cin >> n;
  39. for (int j = 0; j < n; j++)
  40. {
  41. int t;
  42. cin >> t;
  43. a.push_back(t);
  44. }
  45. for (int j = 0; j < n; j++)
  46. {
  47. int t;
  48. cin >> t;
  49. b.push_back(t);
  50. }
  51. check(a, b, n);
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0s 4524KB
stdin
5
3
1 -1 0
1 1 -2
3
0 1 1
0 2 2
2
1 0
1 41
2
-1 0
-1 -41
5
0 1 -1 1 -1
1 1 -1 1 -1
stdout
YES
NO
YES
YES
NO