全部评论 8

  • %%%

    2025-07-28 来自 河北

    1
  • #include <iostream>
    #include <queue>
    #include <vector>
    using namespace std;
    class node {
        public:
            int price, time;
            bool operator<(const node& other) const {
                return time > other.time;
            }
    };
    int main() {
        int n;
        cin >> n;
        priority_queue<node> q;
        long long sum = 0;
        for (int i = 1; i <= n; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            vector<node> v;
            while (!q.empty()) {
                auto f = q.top();
                q.pop();
                if (c - f.time > 45) {
                    continue;
                } else {
                    v.push_back({f.price, f.time});
                }
            }
            for (auto i : v) {
                q.push({i.price, i.time});
            }
            if (a == 0) {
                q.push({b, c});
                sum += b;
            } else {
                bool flag = 0;
                vector<node> v;
                while (!q.empty()) {
                    auto f = q.top();
                    q.pop();
                    if (f.price >= b) {
                        flag = 1;
                        break;
                    } else {
                        v.push_back({f.price, f.time});
                    }
                }
                for (auto i : v) {
                    q.push({i.price, i.time});
                }
                if (flag == 0) {
                    sum += b;
                }
            }
        }
        cout << sum;
        return 0;
    }
    

    其实也可以使用优先队列,我这个也是暴力写法,主要还是数据比较温和,所以说能过。正解应该是使用桶排

    2026-06-14 来自 广东

    0
  • 2025-07-28 来自 河北

    0
  • 2025-07-28 来自 河北

    0
  • 2025-07-28 来自 河北

    0
  • 2025-07-28 来自 河北

    0
  • 2025-07-28 来自 河北

    0
  • 2025-07-28 来自 河北

    0
暂无数据

提交答案之后,这里将显示提交结果~

首页