#include <iostream>
#include <cctype>
#define debug(x) std::cout << #x << " = " << (x) << '\n'
inline __attribute((always_inline)) static void read(int &x){
char c = getchar_unlocked();
x = 0;
while (!isdigit(c)) c = getchar_unlocked();
while (isdigit(c)) x = x * 10 + c - '0',c = getchar_unlocked();
}
const int N = 1e5 + 5;
struct ticket{
bool used;
int time,price;
}a[N];
int main(){
#ifndef ONLINE_JUDGE
freopen("P5661.in","r",stdin);
freopen("P5661.out","w",stdout);
#endif
std::cin.tie(0)->sync_with_stdio(0);
int n,ans = 0,tot = 0;
a[0].time = 0x3f3f3f3f;
for (read(n);n--;){
int op,price,t;
read(op),read(price),read(t);
if (op == 0){
ans += price;
a[++tot] = (ticket){false,t,price};
}
else{
int pos = 0;
for (int i = tot;i;i--){
if (price <= a[i].price && t - a[i].time <= 45 && !a[i].used && a[i].time < a[pos].time) pos = i;
if (t - a[i].time > 45) break;
}
if (pos) a[pos].used = true;
else ans += price;
}
}
std::cout << ans << '\n';
return 0;
}
最优解前几页都开快读的。
意思:本题与队列啥关系