You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 1e5 + 10;
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
struct Ticket {
|
|
|
|
|
int f; // 0 代表地铁,1 代表公交车
|
|
|
|
|
int p; // 第 2 个整数代表第 i 条记录乘车的票价 price[i]
|
|
|
|
|
int t; // 第三个整数代表第 i 条记录开始乘车的时间 ti(距 0 时刻的分钟数)
|
|
|
|
|
} a[N];
|
|
|
|
|
|
|
|
|
|
int ans;
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i].f >> a[i].p >> a[i].t;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
if (a[i].f == 0)
|
|
|
|
|
ans += a[i].p;
|
|
|
|
|
else {
|
|
|
|
|
bool flag = false;
|
|
|
|
|
// 加入了优化点,因为一个站点最少1分钟,所以如果在45分钟以内有效的话,则最多是向前45个站点提供的优惠卷
|
|
|
|
|
// 如果,成功将O(N^2)的时间复杂度,优化为O(N*45)的时间复杂度,因为N高达1e5,所以可以大大降低运行时长
|
|
|
|
|
for (int j = max(i - 45, 1); j < i; j++) {
|
|
|
|
|
if (a[j].f == 0 && a[i].t - a[j].t <= 45 && a[j].p >= a[i].p) {
|
|
|
|
|
flag = true;
|
|
|
|
|
a[j].f = -1; // 优惠票已使用
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag) ans += a[i].p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("%d\n", ans);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|