题解:AT_abc471_d [ABC471D] Chargers

· · 题解

这题属于一眼秒,难度略小。

在一操作中,在 t_i 时间插入电量为 w_i 等价于在初始时,有一块 w_i - t_i 电量的电池,这样我们就可以将它放到优先队列拉。

在二操作中,取出时判断队列是否为空,然后记得将 top+t 与 v 取 \min。这样我们就可以快乐的AC此题。

::::success[code]

#include <bits/stdc++.h>
using namespace std;
long long n, v;
priority_queue<long long> pq;
int main(){
    scanf("%lld %lld", &n, &v);
    while(n--){
        long long op, x, y;
        scanf("%lld %lld", &op, &x);
        if(op==1){
            scanf("%lld", &y);
            pq.push(y - x);
        }else{
            if(!pq.empty()){
                printf("%lld\n", min(v, pq.top() + x));
                pq.pop();
            }else{
                printf("-1\n");
            }
        }
    }
    return 0;
}

::::