#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x[N], g[N], d[N];
bool vis[N];
long long tree[4 * N], lazy[4 * N], pref[N];
void push(int v, int l, int r, int val){
if(l != r){
lazy[v * 2] += val;
lazy[v * 2 + 1] += val;
}
tree[v] += val;
lazy[v] = 0;
}
void update(int v, int l, int r, int ql, int qr, int val){
if(l > r)return;
push(v, l, r, lazy[v]);
if(ql > r || qr < l)return;
if(ql <= l && qr >= r){
push(v, l, r, val);
return;
}
int mid = (l + r) / 2;
update(v * 2, l, mid, ql, qr, val);
update(v * 2 + 1, mid + 1, r, ql, qr, val);
tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
}
int get(int v, int l, int r){
push(v, l, r, lazy[v]);
if(l == r)return l;
int mid = (l + r) / 2;
if(tree[v * 2] + lazy[v * 2] >= 0){
return get(v * 2, l, mid);
}
return get(v * 2 + 1, mid + 1, r);
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> g[i] >> d[i];
pref[i] = pref[i - 1] + g[i];
}
long long ans = 0;
for(int i = 1; i <= n; i++){
if(i > 1)update(1, 1, n, 1, i - 1, x[i - 1] - x[i]);
update(1, 1, n, 1, i, d[i]);
int l = get(1, 1, n);
ans = max(ans, pref[i] - pref[l - 1]);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
368 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
508 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
14 ms |
760 KB |
Output is correct |
12 |
Correct |
15 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
760 KB |
Output is correct |
2 |
Correct |
19 ms |
1016 KB |
Output is correct |
3 |
Correct |
23 ms |
1016 KB |
Output is correct |
4 |
Correct |
117 ms |
3448 KB |
Output is correct |
5 |
Correct |
137 ms |
3448 KB |
Output is correct |
6 |
Correct |
291 ms |
6392 KB |
Output is correct |
7 |
Correct |
222 ms |
6368 KB |
Output is correct |
8 |
Correct |
230 ms |
6444 KB |
Output is correct |
9 |
Correct |
237 ms |
6392 KB |
Output is correct |
10 |
Correct |
215 ms |
6392 KB |
Output is correct |
11 |
Correct |
261 ms |
8696 KB |
Output is correct |
12 |
Correct |
265 ms |
8824 KB |
Output is correct |