fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. #define here cout<<"here\n"
  4. #define pb push_back
  5. #define mp make_pair
  6. using namespace std;
  7.  
  8. const ll mod = 1e9+7;
  9.  
  10. const int MAX = 100005;
  11.  
  12.  
  13. int main()
  14. {
  15. #ifndef ONLINE_JUDGE
  16. freopen("input.txt","r",stdin);
  17. freopen("output.txt","w",stdout);
  18. #endif
  19.  
  20. ios_base::sync_with_stdio(false);
  21. cin.tie(NULL);
  22. int t;
  23. cin>>t;
  24. while(t--)
  25. {
  26. ll n,l,k;
  27. cin>>n>>l>>k;
  28. ll kl;
  29. cin>>kl;
  30. ll A[n],P[n],i,j;
  31. queue<pair<ll,ll> >q;
  32. priority_queue<ll>pq;
  33. vector<pair<ll,ll> >v;
  34. for(i=0;i<n;i++)
  35. cin>>A[i];
  36.  
  37. for(i=0;i<n;i++)
  38. cin>>P[i];
  39.  
  40. for(i=0;i<n;i++)
  41. v.pb(mp(A[i],P[i]));
  42.  
  43. sort(v.begin(),v.end());
  44.  
  45. for(i=0;i<n;i++)
  46. q.push(mp(v[i].first,v[i].second));
  47.  
  48.  
  49.  
  50. ll ti=0;ll cn=0;
  51.  
  52. ll flag=0;ll dam=0;
  53. pair<ll,ll>var;
  54. while((dam>0&&flag==0)||((!q.empty())))
  55. {
  56.  
  57. cn=0;
  58. if(!q.empty())
  59. var=q.front();
  60. else
  61. var=mp((ll)-1,(ll)0);
  62. j=max((ll)0,var.first-l);
  63. ti=ceil((float(j)/k));
  64. ti*=k;
  65. while(var.first!=-1&&var.first-l<=ti)
  66. {
  67. pq.push(var.second);
  68. dam+=var.second;
  69. q.pop();
  70. if(!q.empty())
  71. var=q.front();
  72. else
  73. var=mp((ll)-1,(ll)0);
  74. }
  75. dam-=pq.top();
  76. pq.pop();
  77.  
  78.  
  79. if(dam<kl)
  80. {
  81. kl-=dam;
  82. }
  83. else
  84. {
  85. flag=1;
  86. break;
  87. }
  88.  
  89.  
  90. }
  91. if(kl<=0)
  92. flag=1;
  93.  
  94. if(flag)
  95. cout<<"NO\n";
  96. else
  97. cout<<"YES\n";
  98.  
  99.  
  100.  
  101. }
  102.  
  103. return 0;
  104. }
Runtime error #stdin #stdout 0s 4448KB
stdin
Standard input is empty
stdout
Standard output is empty