IMohammedNasr

Untitled

Mar 26th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 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. vector<ll> v1, v2;
  13. ll n, k;
  14.  
  15. int rec(ll t, int idx);
  16.  
  17. void solve()
  18. {
  19. cin >> n >> k;
  20. v1.resize(n);
  21. v2.resize(n);
  22. for (auto &i : v1)
  23. cin >> i;
  24. for (auto &i : v2)
  25. cin >> i;
  26. int test = max(rec(v1[0], 0), rec(v2[0], 0));
  27. cout << (test == n ? "Yes" : "No") << endl;
  28. }
  29.  
  30. int main()
  31. {
  32. Warding();
  33. int t = 1;
  34. // cin >> t;
  35. while (t--)
  36. {
  37. solve();
  38. }
  39. }
  40.  
  41. int rec(ll t, int idx)
  42. {
  43. if (idx == n - 1)
  44. return 1;
  45. else if (abs(t - v1[idx + 1]) <= k and abs(t - v2[idx + 1]) <= k)
  46. {
  47. return 1 + max(rec(v1[idx + 1], idx + 1), rec(v2[idx + 1], idx + 1));
  48. }
  49. else if (abs(t - v1[idx + 1]) <= k)
  50. return 1 + rec(v1[idx + 1], idx + 1);
  51. else if (abs(t - v2[idx + 1]) <= k)
  52. return 1 + rec(v2[idx + 1], idx + 1);
  53. else
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment