#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, i);
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 |
Incorrect |
1 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Incorrect |
3 ms |
416 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
808 KB |
Output is correct |
2 |
Correct |
19 ms |
1192 KB |
Output is correct |
3 |
Correct |
24 ms |
1144 KB |
Output is correct |
4 |
Correct |
120 ms |
3512 KB |
Output is correct |
5 |
Correct |
134 ms |
3448 KB |
Output is correct |
6 |
Correct |
298 ms |
6528 KB |
Output is correct |
7 |
Correct |
221 ms |
6520 KB |
Output is correct |
8 |
Correct |
226 ms |
6452 KB |
Output is correct |
9 |
Correct |
215 ms |
6524 KB |
Output is correct |
10 |
Incorrect |
213 ms |
6520 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |