fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL)
  5. #define pb push_back
  6. #define int long long int
  7. #define mod 1000000007
  8.  
  9. bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
  10. {
  11. return (a.second < b.second);
  12. }
  13.  
  14. int32_t main()
  15. {
  16. fastIO;
  17. #ifndef ONLINE_JUDGE
  18. freopen("input.txt", "r", stdin);
  19. freopen("output.txt", "w", stdout);
  20. #endif
  21.  
  22. int t;
  23. cin>>t;
  24. assert(1 <=t && t<=100);
  25. while(t--) {
  26. int n,dis,s,kl,i,curr=0;
  27. cin>>n>>dis>>s>>kl;
  28. assert(1<=n && n<=100000);
  29. assert(0<=dis && dis<=1000000000);
  30. assert(1<=s && s<=1000000000);
  31. assert(1<=kl && kl<=1000000000000);
  32. int a[n];
  33. for(i=0;i<n;i++) {
  34. cin>>a[i];
  35. assert(1<=a[i] && a[i]<=1000000000);
  36. }
  37. vector < pair<int,int> > v;
  38. for(i=0;i<n;i++) {
  39. int x;
  40. cin>>x;
  41. assert(0<=x && x<=1000000000);
  42. v.pb({x,a[i]-dis});
  43. }
  44. sort(v.begin(), v.end(), sortbysec);
  45.  
  46. priority_queue < pair<int,int> > pq;
  47. int tim=0,dam=0;
  48. while(curr<n && v[curr].second<=0) {
  49. pq.push(v[curr]);
  50. dam+=v[curr].first;
  51. curr++;
  52. }
  53. if(pq.size()>0) {
  54. dam-=pq.top().first;
  55. pq.pop();
  56. kl-=dam;
  57. tim=1;
  58. }
  59. while(curr<n) {
  60. int r=v[curr].second;
  61. if(r%s==0)
  62. r=r/s;
  63. else
  64. r=r/s+1;
  65. int len=pq.size();
  66. int x=min(len,r-tim);
  67. while(x>0) {
  68. dam-=pq.top().first;
  69. pq.pop();
  70. kl-=dam;
  71. x--;
  72. }
  73. tim=r;
  74. while(curr<n && v[curr].second<=s*r) {
  75. pq.push(v[curr]);
  76. dam+=v[curr].first;
  77. curr++;
  78. }
  79. }
  80. while(pq.size()>0) {
  81. dam-=pq.top().first;
  82. pq.pop();
  83. kl-=dam;
  84. }
  85. if(kl<=0)
  86. cout<<"NO\n";
  87. else
  88. cout<<"YES\n";
  89. }
  90. return 0;
  91. }
Runtime error #stdin #stdout #stderr 0s 4372KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog: prog.cpp:24: int32_t main(): Assertion `1 <=t && t<=100' failed.