38 lines
1.0 KiB
C++
38 lines
1.0 KiB
C++
#include <bits/stdc++.h>
|
||
|
||
using namespace std;
|
||
const int N = 1e5 + 10;
|
||
int n;
|
||
|
||
struct Node {
|
||
int f;
|
||
int p;
|
||
int t;
|
||
} 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;
|
||
} |