fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int t;
  7. cin >> t;
  8. while(t--){
  9. int n;
  10. vector<int> a;
  11. vector<int> b;
  12. int diff=0,idx=0;
  13. bool flag = true;
  14. cin >> n;
  15. for(int i = 0; i < n; i++){
  16. int x;
  17. cin >> x;
  18. a.push_back(x);
  19. }
  20. for(int i = 0; i < n; i++){
  21. int x;
  22. cin >> x;
  23. b.push_back(x);
  24. if(x > a[i] && x - a[i] > diff){
  25. diff = x - a[i];
  26. idx = i;
  27. }
  28. }
  29. for(int i=0;i < n;i++){
  30. if(i == idx) continue;
  31. if((a[i] - diff) < 0 || (a[i] - diff) < b[i]){
  32. flag = false;
  33. break;
  34. }
  35. }
  36. if(flag)
  37. cout << "YES\n";
  38. else
  39. cout << "NO\n";
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty