#include <bits/stdc++.h>
#define int long long
#define pii pair <int , int>
#define fi first
#define se second
#define arr3 array <int , 3> 
using namespace std;
const int INF = 1e9;
const int maxn = 5e5 + 7;
// brute để hiểu đề 
int n , ps[maxn];
arr3 a[maxn];
void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++) 
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    sort(a+1 , a+n+1);
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int sumg = 0;
        int sumd = 0;
        for(int j = i; j >= 1; j--)
        {
            int len = a[i][0] - a[j][0];
            sumg += a[j][1];
            sumd += a[j][2];
            if(sumd >= len)
            {
                ans = max(ans , sumg);
            }
        }
    }
    cout << ans << '\n';
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    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... |