3487. 【NOIP2013模拟联考11】剑与魔法(dragons) (Standard IO)
Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits
Goto ProblemSet做法:打一个优先队列实时维护即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; priority_queue<int> q; int n; char c; long long ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x = 0; cin >> c; if (c == 'c') { scanf("%d", &x); x = -x; q.push(x); } else { scanf("%d", &x); while (q.size() >= x && i != n) q.pop(); } } while (!q.empty()) { int x = q.top(); x = -x; ans += x; q.pop(); } printf("%d", ans); }