Advertisement
og86

sort p soln

Dec 19th, 2022
5,524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5. void solveCase()
  6. {
  7. int n, k;
  8. cin >> n >> k;
  9. vector<int> h(n), p(n);
  10. for (auto &i : h)
  11. cin >> i;
  12.  
  13. for (auto &i : p)
  14. cin >> i;
  15.  
  16. vector<int> ord(n);
  17. iota(ord.begin(), ord.end(), 0);
  18. sort(ord.begin(), ord.end(), [&](auto x, auto y) { return p[x] < p[y]; });
  19.  
  20. int dmg = 0;
  21. bool f = true;
  22. for (int i : ord)
  23. {
  24. if (h[i] <= dmg)
  25. continue;
  26.  
  27. if (i != ord[0])
  28. k -= p[i];
  29.  
  30. if (k > 0)
  31. {
  32. dmg += k;
  33. while (h[i] > dmg)
  34. {
  35. k -= p[i];
  36. if (k < 0)
  37. break;
  38. dmg += k;
  39. }
  40. }
  41.  
  42. if (h[i] > dmg)
  43. {
  44. cout << "NO\n";
  45. return;
  46. }
  47. }
  48.  
  49. cout << "YES\n";
  50. }
  51.  
  52. int32_t main()
  53. {
  54. ios::sync_with_stdio(false), cin.tie(NULL);
  55. int t = 0;
  56. cin >> t;
  57. while (t--)
  58. solveCase();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement