#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pw(x) (1ll << x)
#define sz(x) (int)((x).size())
#define pb push_back
#define endl '\n'
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T>
using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
const int N = 3e5 + 100;
int t[N << 2];
inline int get (int v, int tl, int tr, int x, int R) {
if (tl == tr) { return tl; }
int tm = (tl + tr) >> 1;
if (t[v << 1] >= x && tl <= R) return get(v << 1, tl, tm, x, R);
if (t[v << 1 | 1] >= x && tm + 1 <= R) return get(v << 1 | 1, tm + 1, tr, x, R);
return -1;
}
inline void upd (int v, int tl, int tr, int p, int x) {
if (tl == tr) { t[v] = x; return; }
int tm = (tl + tr) >> 1;
if (p <= tm) upd(v << 1, tl, tm, p, x);
else upd(v << 1 | 1, tm + 1, tr, p, x);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
inline void solve () {
int n; cin >> n;
vector <int> x (n + 1), g (n + 1), pd (n + 1), pg (n + 1);
vector <int> cmp;
for (int i = 1; i <= n; ++i) {
int d; cin >> x[i] >> g[i] >> d;
pd[i] = pd[i - 1] + d;
pg[i] = pg[i - 1] + g[i];
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
upd(1, 1, n, i, x[i] - pd[i - 1]);
int p = get(1, 1, n, x[i] - pd[i], i);
if (~p) umax(ans, pg[i] - pg[p - 1]);
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
3 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
3 ms |
704 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
4 ms |
1016 KB |
Output is correct |
27 |
Correct |
5 ms |
956 KB |
Output is correct |
28 |
Correct |
19 ms |
3936 KB |
Output is correct |
29 |
Correct |
19 ms |
4172 KB |
Output is correct |
30 |
Correct |
40 ms |
8400 KB |
Output is correct |
31 |
Correct |
39 ms |
7160 KB |
Output is correct |
32 |
Correct |
42 ms |
7244 KB |
Output is correct |
33 |
Correct |
37 ms |
7044 KB |
Output is correct |
34 |
Correct |
38 ms |
7036 KB |
Output is correct |
35 |
Correct |
40 ms |
7552 KB |
Output is correct |
36 |
Correct |
43 ms |
7756 KB |
Output is correct |