#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
vector<int> t;
int getmin(int v, int tl, int tr, int l, int r) {
if (tl > tr || l > r) return 1e15;
if (tl == l && tr == r) return t[v];
int tm = (tl + tr) >> 1;
return min(getmin(2 * v, tl, tm, l, min(r, tm)), getmin(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void upd(int v, int tl, int tr, int x, int pos) {
if (tl == tr) {
t[v] = min(t[v], x);
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm) {
upd(2 * v, tl, tm, x, pos);
}
else upd(2 * v + 1, tm + 1, tr, x, pos);
t[v] = min(t[2 * v], t[2 * v + 1]);
}
int32_t main() {
int n;
cin >> n;
vector<vector<int>> a;
for (int i = 0; i < n; ++i) {
int x, g, e;
cin >> x >> g >> e;
a.push_back({ x,g,e });
}
vector<int> pr(n + 1);
for (int i = 0; i < n; ++i) {
pr[i + 1] = pr[i] + a[i][2];
}
vector<int> pr_gold(n + 1);
for (int i = 0; i < n; ++i) {
pr_gold[i + 1] = pr_gold[i] + a[i][1];
}
vector<int> coord;
for (int i = 0; i < n; ++i) {
coord.push_back(pr[i] - a[i][0]);
coord.push_back(pr[i + 1] - a[i][0]);
}
sort(coord.begin(), coord.end());
coord.erase(unique(coord.begin(), coord.end()), coord.end());
int N = coord.size();
t.resize(4 * N, 1e15);
int ans = 0;
for (int i = 0; i < n; ++i) {
if (i == 0) {
ans = max(ans, a[i][1]);
int pos = lower_bound(coord.begin(), coord.end(), pr[i] - a[i][0]) - coord.begin();
upd(1, 0, N - 1, pr_gold[i], pos);
}
else {
int pos = lower_bound(coord.begin(), coord.end(), pr[i + 1] - a[i][0]) - coord.begin();
int x = getmin(1, 0, N - 1, 0, pos);
ans = max(ans, pr_gold[i + 1] - x);
ans = max(ans, a[i][1]);
pos = lower_bound(coord.begin(), coord.end(), pr[i] - a[i][0]) - coord.begin();
upd(1, 0, N - 1, pr_gold[i], pos);
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
640 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
3 ms |
620 KB |
Output is correct |
22 |
Correct |
3 ms |
620 KB |
Output is correct |
23 |
Correct |
9 ms |
1260 KB |
Output is correct |
24 |
Correct |
9 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
640 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
3 ms |
620 KB |
Output is correct |
22 |
Correct |
3 ms |
620 KB |
Output is correct |
23 |
Correct |
9 ms |
1260 KB |
Output is correct |
24 |
Correct |
9 ms |
1536 KB |
Output is correct |
25 |
Correct |
7 ms |
1280 KB |
Output is correct |
26 |
Correct |
14 ms |
2236 KB |
Output is correct |
27 |
Correct |
16 ms |
2216 KB |
Output is correct |
28 |
Correct |
85 ms |
9760 KB |
Output is correct |
29 |
Correct |
109 ms |
10144 KB |
Output is correct |
30 |
Correct |
233 ms |
20144 KB |
Output is correct |
31 |
Correct |
174 ms |
18984 KB |
Output is correct |
32 |
Correct |
166 ms |
19100 KB |
Output is correct |
33 |
Correct |
162 ms |
18844 KB |
Output is correct |
34 |
Correct |
162 ms |
18716 KB |
Output is correct |
35 |
Correct |
185 ms |
19356 KB |
Output is correct |
36 |
Correct |
183 ms |
19672 KB |
Output is correct |