hpnq

Untitled

Jun 7th, 2022
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define all(x) x.begin(), x.end()
  4. #define small_black_cock cout
  5. using namespace std;
  6. using ll = long long;
  7.  
  8.  
  9.  
  10.  
  11. int main() {
  12. int t;
  13. cin >> t;
  14. for(int k = 0; k < t; k++){
  15. int n ;
  16. cin >> n;
  17. vector<int> a(n), b(n), d(n);
  18. for(int i = 0; i < n; i++) cin >> a[i];
  19. for(int i = 0; i < n; i++) cin >> b[i];
  20. bool flag = false;
  21. int nozero = -1, zero = -1;
  22. for(int i =0; i < n; i++){
  23. if(b[i] == 0){
  24. d[i] = a[i];
  25. if(nozero != -1){
  26. if(d[i] > d[nozero]){
  27. flag = true;
  28. break;
  29. }
  30. }
  31. zero = i;
  32. }else{
  33. d[i] = a[i] - b[i];
  34. if(d[i] < 0){
  35. flag = true;
  36. break;
  37. }
  38. if(zero != -1){
  39. if(d[zero] > d[i]){
  40. flag = true;
  41. break;
  42. }
  43. zero = -1;
  44.  
  45. }
  46. if(nozero != -1){
  47. if(d[nozero] > d[i]){
  48. flag = true;
  49. break;
  50. }
  51. }
  52. nozero = i;
  53. // cout << nozeroID << " ";
  54. }
  55.  
  56.  
  57. }
  58.  
  59. if(!flag){
  60. cout<< "YES" << "\n";
  61. }else{
  62. cout << "NO" << "\n";
  63. }
  64.  
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment