#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
struct SegmentTree{
vector<int> a; int sz = 1, ID = 1e18;
SegmentTree(vector<int> &v){
while(sz < (int)v.size()) sz += sz;
a.assign(2*sz, ID);
build(v, 0, 0, sz);
}
void build(vector<int> &v, int x, int lx, int rx){
if(rx-lx==1){
if(lx<(int)v.size()) a[x] = v[lx];
return;
}
int mx = (lx+rx)/2;
build(v, 2*x+1, lx, mx);
build(v, 2*x+2, mx, rx);
a[x] = min(a[2*x+1], a[2*x+2]);
}
int get(int val, int x, int lx, int rx){
if(rx-lx==1) return (a[x] <= val ? lx : sz);
int mx = (lx+rx)/2;
if(a[2*x+1]<=val) return get(val, 2*x+1, lx, mx);
if(a[2*x+2]<=val) return get(val, 2*x+2, mx, rx);
return sz;
}
int get(int val){ return get(val, 0, 0, sz); }
};
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, ans = 0; cin >> n;
vector<int> a(n+1), b(n+1), c(n+1);
for(int i=1; i<=n; ++i){
cin >> c[i] >> b[i] >> a[i];
a[i] += a[i-1];
b[i] += b[i-1];
}
for(int i=1; i<=n; ++i) a[i] -= c[i];
SegmentTree st(a);
for(int i=1; i<=n; ++i){
int j = max(st.get(a[i]), 1LL);
if(j<=i) ans = max(ans, b[i] - b[j-1]);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |