题解: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;
}
本文来自博客园,作者:KukCair,转载请注明原文链接:https://www.cnblogs.com/KukCair/p/18564689

浙公网安备 33010602011771号