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 @   Uzhia  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示