Chargers

Problem Link

Solution by dudu — 100 pts

Code / Notes

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    int Q, V;
    cin >> Q >> V;

    priority_queue<int> pq;
    for (int i = 0; i < Q; i++) {
        int op, t;
        cin >> op >> t;

        if (op == 1) {
            int x;
            cin >> x;
            pq.push(x-t);
        } else {
            if (pq.empty()) cout << -1 << endl;
            else {
                cout << min(pq.top()+t, V) << endl;
                pq.pop();
            }
        }
    }
}

Last updated 1 month ago


« Back to problem