#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define exit exit(false)
//#define here() cerr << "herewego\n";
#define show(x) cerr << #x << ": " << x << '\n';
#define int long long
//#define double long double
#define all(a) a.begin(), a.end()
#define whole(a, p, q) a+p, a+p+q
#define ioio() ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int sz = 100007;
int n, x[sz], g[sz], d[sz], p[sz], pp[sz], mx, mxx, t[sz*4];
void upd (int v, int tl, int tr, int val, int pos) {
if (tl == tr) {
t[v] = val;
return;
}
int tm = (tl + tr) >> 1;
int lf = (v << 1);
int rg = (v << 1 | 1);
if (pos <= tm) {
upd (lf, tl, tm, val, pos);
} else {
upd (rg, tm+1, tr, val, pos);
}
t[v] = max (t[lf], t[rg]);
}
void upd (int val, int pos) {
return upd (1, 1, n, val, pos);
}
int get (int v, int tl, int tr, int val) {
if (tl == tr) {
return tl;
}
int tm = (tl + tr) >> 1;
int lf = (v << 1);
int rg = (v << 1 | 1);
if (t[rg] >= val) {
return get (rg, tm+1, tr, val);
}
return get (lf, tl, tm, val);
}
int get (int val) {
return get (1, 1, n, val);
}
signed main () { ioio();
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> g[i] >> d[i];
p[i] = p[i-1] + d[i];
pp[i] = pp[i-1] + g[i];
upd (p[i] - x[i], i);
}
for (int i = 1; i <= n; i++) {
int e = get (p[i-1] - x[i]);
// show(e);
mx = max (mx, pp[e] - pp[i-1]);
}
cout << mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 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 |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
748 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 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 |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
748 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
3 ms |
748 KB |
Output is correct |
26 |
Correct |
5 ms |
1004 KB |
Output is correct |
27 |
Correct |
7 ms |
1004 KB |
Output is correct |
28 |
Correct |
26 ms |
3308 KB |
Output is correct |
29 |
Correct |
27 ms |
3328 KB |
Output is correct |
30 |
Correct |
55 ms |
6252 KB |
Output is correct |
31 |
Correct |
48 ms |
6252 KB |
Output is correct |
32 |
Correct |
50 ms |
6252 KB |
Output is correct |
33 |
Correct |
48 ms |
6252 KB |
Output is correct |
34 |
Correct |
49 ms |
6252 KB |
Output is correct |
35 |
Correct |
52 ms |
6252 KB |
Output is correct |
36 |
Correct |
53 ms |
6252 KB |
Output is correct |