30分求调(用的队列)
查看原帖
30分求调(用的队列)
970949
CleverSea楼主2024/10/3 00:46

rt,点我看测试点数据,求大佬指点!

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

int n, ans;

struct Node
{
    int p, t;
};

queue<Node> q;

signed main()
{
    cin >> n;
    while (n--)
    {
        int a, p, t;
        cin >> a >> p >> t;
        while (!q.empty() && t - (q.front()).t > 45) q.pop();
        if (a == 0)
        {
            q.push({p, t});
            ans += p;
        }
        else
        {
            if (!q.empty() && (q.front()).p >= p) q.pop();
            else ans += p;
        }
    }
    cout << ans << endl;
    return 0;
}

2024/10/3 00:46
加载中...