题解:CF644B Processing Queries

CF644B Processing Queries

基本思路

模拟题。

对于每个工作申请,队列有如下两种操作:

首先,将 \(\leq\) 当前开始时间(即 \(t_i\))的所有操作弹出。

接下来有两种选择:

  • 当队列已满,直接输出 -1

  • 当队列未满,更新结束时间并入队,输出新结束时间。

代码实现

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, b, nw;
queue<int> q;
signed main(){
    cin >> n >> b;
    while(n--){
        int t, d;
        cin >> t >> d;
        while(!q.empty() && q.front() <= t) q.pop();
        if(q.size() > b) cout << "-1 ";
        else{
            nw = max(nw, t) + d;
            q.push(nw);
            cout << nw << ' ';
        }
    }
    return 0;
}
posted @ 2024-11-23 16:10  KukCair  阅读(23)  评论(0)    收藏  举报