1 solutions

  • 0
    @ 2023-8-27 22:05:37
    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 100005;
    struct Ticket {
        int price, time, used;
    } q[MAXN];
    int head, tail, n, cost;
    int main() {
        cin >> n;
        for (int i = 0; i < n; i++) {
            int op, price, time;
            cin >> op >> price >> time;
            if (op == 0) {
                cost += price;
                q[tail].time = time + 45;
                q[tail++].price = price;
            } 
            else {
                while (head < tail && q[head].time < time) {
                    head++;
                }
                bool found = 0;
                for (int j = head; j < tail; j++) {
                    if (q[j].price >= price && q[j].used == 0) {
                        found = 1;
                        q[j].used = 1;
                        break;
                    }
                }
                if (found==0){
                    cost += price;
                } 
            }
        }
        cout<<cost<<"\n";
        return 0;
    }
    
    • 1

    Information

    ID
    6813
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    # Submissions
    41
    Accepted
    8
    Uploaded By