Advertisement
Zeinab_Hamdy

Untitled

Mar 12th, 2023
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned ll
  5. #define nl "\n"
  6. #define sz(x) int(x.size())
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  9. #define PI 3.141592654
  10. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fi first
  14. #define se second
  15. #define cin(v) for (auto&i:v) cin >> i;
  16. #define cout(v) for (auto&i:v) cout << i << " ";
  17. #define fixed(n) fixed << setprecision(n)
  18. //#define MOD  1e9 + 7
  19.  
  20.  
  21. void IO(){
  22.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  23. }
  24. void files(){
  25.     //freopen("filename.in" , "r" ,stdin);
  26.             #ifndef ONLINE_JUDGE
  27.               freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout);
  28.             #endif
  29. }
  30.  
  31.  
  32.  
  33. void solve(){
  34.  
  35.  
  36.  
  37. ll n , k , d , w;
  38.  
  39. cin >> n >> k >> d >> w;
  40.  
  41. vector < ll > v(n);
  42.  
  43. for(int i=0;i<n;i++){
  44.     cin >> v[i];
  45.    v[i]+=w;
  46. }
  47.  
  48. ll ans = 0  , start =0 , tempK = k;
  49.  
  50. for(int i =0 ; i < n ;i++){
  51.  
  52.   // start point
  53.    if(k == tempK){
  54.        ans++ ;
  55.        start= v[i];
  56.        k--;
  57.        continue;
  58.    }
  59.      
  60.        if(k > 0 and  (abs(v[i] - start) <= d ) or ( abs(v[i]- w - start) <= d )){
  61.            k-- ;
  62.            
  63.            if( k ==0)
  64.                k= tempK;
  65.        }
  66.        
  67.        else // start new dose
  68.            k = tempK-1 , start = v[i] ,  ans++;
  69. }
  70.  
  71.  
  72. cout << ans << nl;
  73.  
  74. }
  75.  
  76.  
  77. int main(){
  78.                  IO();       //  files();
  79.  
  80.     int testCase=1;  // one test case
  81.      cin >> testCase ;      
  82.  while(testCase--)
  83.         solve();  // my code
  84.        
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement