Nebius Welcome Round (Div. 1 + Div. 2) B. Vaccination

link

Code

// #include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <cctype>
#include <list>
#include <bitset>
#define dbg(x) cout << #x << " = " << x << "\n"
using namespace std;
#define cf int _o_o_;cin>>_o_o_;for (int Case = 1; Case <= _o_o_;Case++)
#define SZ(x) (int)(x.size())
inline void solve();
int main() {solve();return 0;}
// ios::sync_with_stdio(false), cin.tie(nullptr);
 
using ll = long long;
const int maxn = 2e5 + 10;

void ok();
inline void solve() {
    int t;
    cin >> t;
    while (t -- ) {
        ok();
    }
}

inline void ok() {
    int n, k, d, w;
    cin >> n >> k >> d >> w;
    deque<pair<int,int>> dq;
    int ans = 0;
    // 贪心策略:在第一个病人即将走的时候给他药。
    for (int i = 0;i < n;i++) {
        int x;
        cin >> x;
        if (SZ(dq) != 0 && x > dq.front().first + d)    // 如果队头的这袋药在时间x已经过期了,就丢掉这些药。
            dq.pop_front();  

        if (SZ(dq) ==  0) { // 如果当前队列是空的,
            dq.push_back({x + w, k});   // 在第i个病人即将要走的时候,打开一袋药。那么后面一定有药。
            ans ++; // 又打开了一袋药,答案加一
        }
        dq.front().second --;   // 给当前病人i一包药。当前时间是dq.front().first
        if (dq.front().second == 0) dq.pop_front();     // 给了病人i后,这袋药用完了,丢掉。
    }
    cout << ans << "\n";
}

posted @ 2023-03-15 16:01  Uzhia  阅读(19)  评论(0)    收藏  举报