| ac | ac | ac | ac | ac | ac | ac | tle | | tle | tle | tle | tle | ac | ac | tle | tle | tle | tle | tle | tle |
|---|
#include <bits/stdc++.h>
using namespace std;
struct ride {
int bus_or_subway;
int price;
int All_time;
int time;
};
struct li_r {
int price;
int time;
};
ride a[100002];
li_r b[100002];
int cnt = 0 , ans = 0;
int main() {
int n;
cin >> n >> a[1].bus_or_subway >> a[1].price >> a[1].All_time;
if ( a[1].bus_or_subway == 0 ) {
b[ ++ cnt ].price = a[1].price;
b[ cnt ].time = a[1].All_time;
}
ans += a[1].price;
for ( int i = 2; i <= n; i ++ ) {
cin >> a[i].bus_or_subway >> a[i].price >> a[i].All_time;
a[ i - 1 ].time = a[i].All_time - a[ i - 1 ].All_time;
}
for ( int i = 2; i <= n; i ++ ) {
if ( a[i].bus_or_subway == 0 ) {
b[ ++ cnt ].price = a[i].price;
b[ cnt ].time = a[i].All_time;
ans += a[i].price;
}
else {
bool flag = false;
for ( int j = 1; j <= cnt; j ++ ) {
if ( ( a[i].All_time - b[j].time <= 45 ) && ( a[i].price <= b[j].price ) && b[j].price != 0 ) {
b[j].price = 0;
b[j].time = 0;
flag = true;
break;
}
}
if ( flag ) {
continue;
}
ans += a[i].price;
}
// cout << ans << "\n";
}
cout << ans;
return 0;
}