#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int inf=1e17;
const int N=1e5+5;
const int N1=1e5+5;
const int N2=5e6+6;
const int mod=1e9+7;
const int k1=447;
struct edge{
    int d,in;
};
struct edge1{
    int x,g,d;
};
vector<edge1>v;
int dp[N];
int dp1[N];
signed main(){
boost;
    int n;
    cin>>n;
    v.push_back({0,0,0});
    for(int i=1;i<=n;i++){
        edge1 x;
        cin>>x.x>>x.g>>x.d;
        dp[i]=dp[i-1]+x.g;
        dp1[i]=dp1[i-1]+x.d;
        v.push_back(x);
    }
    int l=1;
    int ans=0;
    for(int r=1;r<=n;r++){
        while(v[r].x-v[l].x>dp1[r]-dp1[l-1]&&l<r){
            l++;
        }
        ans=max(ans,dp[r]-dp[l-1]);
    }
    cout<<ans;
}  
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |