跳到正文

个人记录

xxx

yl_lsj约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前

#include <iostream> #include <deque> using namespace std;

int main() { ios::sync_with_stdio(false); cin.tie(nullptr);

C++
deque<pair<long long, long long>> dq; // 存储(值,数量)对
int Q;
cin >> Q;

while (Q--) {
    int type;
    cin >> type;

    if (type == 1) {
        long long x, c;
        cin >> x >> c;
        dq.push_back({x, c}); // 添加到队尾
    } else {
        long long k;
        cin >> k;
        long long sum = 0;

        while (k > 0) {
            auto &front = dq.front();
            long long take = min(k, front.second);
            sum += take * front.first;
            front.second -= take;
            k -= take;

            if (front.second == 0) {
                dq.pop_front(); // 如果取完了就弹出
            }
        }

        cout << sum << "\n";
    }
}

return 0;

}

原文