P5661 公交换乘

it2023-03-29  76

#include <iostream> 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 = false; for (int j = head; j < tail; ++j) { if (q[j].price >= price && q[j].used == 0) { found = true; q[j].used = 1; break; } } if (!found) cost += price; } } cout << cost << endl; return 0; }
最新回复(0)