#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define lb lower_bound
#define F first
#define S second
#define sz size()
#define int long long
#define all(v) v.begin(),v.end()
#define FOR1(x, n) for(int j = x; j <= n; j ++)
#define FOR(x, n, m, d) for(int x = n; x <= m; x += d)
#define FORR(x, n, m, d) for(int x = n; x >= m; x -= d)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
const int N = 5e5+5;
int a[N], b[N], pref[N], d[N], c[N], ans, e[N];
int n,m,sum=0,x,y, r, cnt, l, mod = 998244353, inf = -1e18, k;
string s, str;
void dnc(int l = 1, int r = n){
if(l==r)ans = max(ans, b[l]);
if(l >= r)return;
int md = (l+r) >> 1;
dnc(l, md), dnc(md+1, r);
map<int, int>mp;
int prefix = 0, prefix1 = 0;
FOR(i, md+1, r, 1){
prefix += c[i];
prefix1 += b[i];
mp[a[i] - prefix] = prefix1;
}
prefix = prefix1 = 0;
FORR(i, md, l, 1){
prefix += c[i];
prefix1 += b[i];
if(mp[a[i] + prefix])
ans = max( mp[a[i] + prefix] + prefix1, ans);
}
}
void solve(){
cin >> n;
FOR(i,1,n,1){
cin>>a[i]>>b[i]>>c[i];
}
dnc();
cout << ans;
}
signed main(){
nikita
int tt = 1;
if(!tt)cin >> tt;
FOR(i, 1, tt, 1){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |