#include <iostream>
#include <list>
using namespace std;
int main() {
int n, x, y, z, sum = 0;
cin >> n;
list<pair<int, int>> li;
for(int i = 0; i < n; ++i) {
cin >> x >> y >> z;
if(x == 0) {
sum += y;
li.push_back( {y, z} );
} else {
int h = 0, sj = 0;
while(!li.empty()) {
auto p = li.front();
li.erase( li.begin() );
if(p.second + 45 >= z) {
h += p.first;
if(sj == 0) {
sj = p.second;
}
}
if(h > y) {
break;
}
}
if(h < y) {
sum += y;
} else if(h > y){
li.insert(li.begin(), {h-y, sj});
}
}
}
cout << sum;
return 0;
}
想不到有那错了!!!