P5661 [CSP-J 2019] 公交换乘
#include<iostream>
#include<queue>
#include<list>
#include<algorithm>
#define ll long long
using namespace std;
struct node {
int t;
int v;
};
ll n,w,p,t1,t2,ans=0;
queue<node> q;
int main() {
cin>>n;
for(int i=1; i<=n; i++) {
cin>>w>>p>>t2;
if(w==0) {
node cnt= {t2,p};
ans+=p;
q.push(cnt);
} else {
if(!q.empty()) {
while(t2-q.front().t>45 && q.front().v>=p && !q.empty()) {
q.pop();
}
if(!q.empty()) {
q.pop();
} else ans+=p;
} else ans+=p;
}
}
cout<<ans<<endl;
return 0;
}