This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
 
using namespace std;
 
ll n, x, g, d;
 
int main() {
    cin >> n;
    ll prefd[n], prefg[n], xx[n];
    for (int i = 0; i < n; i++) {
        cin >> x >> g >> d;
        xx[i] = x;
        if (i == 0) {
            prefg[i] = g;
            prefd[i] = d;
        }
        else {
            prefd[i] = prefd[i - 1] + d;
            prefg[i] = prefg[i - 1] + g;
        }
    }
    ll mx = 0;
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j >= i; j--) {
            if (i == 0){
                if (xx[j] - xx[i] <= prefd[j]) {
                    mx = max(mx, prefg[j]);
                }
            } else if (xx[j] - xx[i] <= prefd[j] - prefd[i - 1]) {
                mx = max(mx, prefg[j] - prefg[i - 1]);
            }
        }
    }
    cout << mx;
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |