#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6 + 5, M = 2e14;
int n;
ll x[N], g[N], d[N];
map<ll, ll> tree;
void upd(ll k, ll x) {
while (k < M) {
if (tree.find(k) == tree.end()) {
tree[k] = x;
} else {
tree[k] = min(tree[k], x);
}
k += k & -k;
}
}
ll que(ll k) {
ll ans = LLONG_MAX;
while (k) {
if (tree.find(k) != tree.end()) {
ans = min(ans, tree[k]);
}
k -= k & -k;
}
return ans;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> g[i] >> d[i];
d[i] += d[i - 1];
g[i] += g[i - 1];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
upd(d[i - 1] - x[i] + M / 2, g[i - 1]);
ans = max(ans, g[i] - que(d[i] - x[i] + M / 2));
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
1024 KB |
Output is correct |
18 |
Correct |
8 ms |
1536 KB |
Output is correct |
19 |
Correct |
6 ms |
1024 KB |
Output is correct |
20 |
Correct |
7 ms |
1024 KB |
Output is correct |
21 |
Correct |
6 ms |
768 KB |
Output is correct |
22 |
Correct |
7 ms |
1024 KB |
Output is correct |
23 |
Correct |
21 ms |
3456 KB |
Output is correct |
24 |
Correct |
22 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
1024 KB |
Output is correct |
18 |
Correct |
8 ms |
1536 KB |
Output is correct |
19 |
Correct |
6 ms |
1024 KB |
Output is correct |
20 |
Correct |
7 ms |
1024 KB |
Output is correct |
21 |
Correct |
6 ms |
768 KB |
Output is correct |
22 |
Correct |
7 ms |
1024 KB |
Output is correct |
23 |
Correct |
21 ms |
3456 KB |
Output is correct |
24 |
Correct |
22 ms |
3456 KB |
Output is correct |
25 |
Correct |
26 ms |
1920 KB |
Output is correct |
26 |
Correct |
57 ms |
3960 KB |
Output is correct |
27 |
Correct |
61 ms |
7032 KB |
Output is correct |
28 |
Correct |
347 ms |
34344 KB |
Output is correct |
29 |
Correct |
351 ms |
34680 KB |
Output is correct |
30 |
Correct |
852 ms |
100784 KB |
Output is correct |
31 |
Correct |
723 ms |
68476 KB |
Output is correct |
32 |
Correct |
727 ms |
68600 KB |
Output is correct |
33 |
Correct |
670 ms |
35576 KB |
Output is correct |
34 |
Correct |
456 ms |
23900 KB |
Output is correct |
35 |
Correct |
512 ms |
49840 KB |
Output is correct |
36 |
Correct |
539 ms |
49400 KB |
Output is correct |