是不是有的地方思路比较麻烦啊。。。
#include<bits/stdc++.h>
#define For(i,s,e) for(int i = s;i <= e;i++)
#define Rof(i,s,e) for(int i = s;i >= e;i--)
using namespace std;
typedef long long ll;
template <typename T>
inline void read(T &x) {
char ch = getchar();
T f = 1;
x = 0;
while(ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = x*10 + ch-'0';
ch = getchar();
}
x*= f;
}
const int maxn = 1e5+10;
int n;
ll trans[maxn],price[maxn],stim[maxn];
struct tkt{
bool have;ll pri;ll timsat;
}ticket[maxn];
int main() {
read(n);
ll sum = 0;
int x = 1;
For(i,1,n){
read(trans[i]),read(price[i]),read(stim[i]);
sum+= price[i];
if(!trans[i]){
ticket[x].have = true;
ticket[x].pri = price[i];
ticket[x].timsat = stim[i];
++x;
}
}
ll ans = sum;
For(i,1,n){
if(trans[i]){
For(j,1,x-1){
if(ticket[j].have && (((stim[i]-ticket[j].timsat) > 0)&&(stim[i]-ticket[j].timsat) <=45) && ticket[j].pri >= price[i]){
ticket[j].have = false;
ans-= price[i];
//printf("%lld ",stim[i]);
//printf("%lld\n",(stim[i]-ticket[j].timsat));
break;
}
}
}else{
continue;
}
}
printf("%lld",ans);
return 0;
}