IMohammedNasr

Untitled

Mar 26th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void Warding()
  6. {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  10. #endif
  11. }
  12.  
  13. void solve()
  14. {
  15. bool flag = 0, c1 = 1, c2 = 1, c3 = 1, c4 = 1;
  16. ll n, k;
  17. cin >> n >> k;
  18. vector<ll> v1(n), v2(n);
  19. for (auto &i : v1)
  20. cin >> i;
  21. for (auto &i : v2)
  22. cin >> i;
  23. if (n == 1)
  24. {
  25. cout << (abs(v1[0] - v2[0]) <= k ? "Yes" : "No") << endl;
  26. return;
  27. }
  28. for (int i = 1; i < n - 1; i++)
  29. {
  30. if ((abs(v1[i] - v2[i + 1]) <= k and (c1 or c4)) or (abs(v1[i] - v1[1 + i]) <= k and (c1 or c4)) or (abs(v2[i] - v1[i + 1]) <= k and (c2 or c3)) or (abs(v2[i] - v2[1 + i]) <= k and (c2 or c3)))
  31. {
  32. flag = true;
  33. if (abs(v1[i] - v2[i + 1]) <= k)
  34. c2 = true;
  35. else
  36. c2 = false;
  37. if (abs(v2[i] - v2[1 + i]) <= k)
  38. c3 = true;
  39. else
  40. c3 = false;
  41. if (abs(v2[i] - v1[i + 1]) <= k)
  42. c1 = true;
  43. else
  44. c1 = false;
  45. if (abs(v1[i] - v1[1 + i]) <= k)
  46. c4 = true;
  47. else
  48. c4 = false;
  49. }
  50. else
  51. {
  52. flag = false;
  53. break;
  54. }
  55. }
  56. cout << (flag ? "Yes" : "No") << endl;
  57. }
  58.  
  59. int main()
  60. {
  61. Warding();
  62. int t = 1;
  63. // cin >> t;
  64. while (t--)
  65. {
  66. solve();
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment