#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;

struct Block
{
    int w, s, v;
}a[1005];

int N;
LL dp[20005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    //freopen("1.out", "w", stdout);
    #endif

    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> a[i].w >> a[i].s >> a[i].v;

    sort(a + 1, a + N + 1,
         [](Block x, Block y) { return (x.w + x.s) < (y.w + y.s); });

    for(int i = 1; i <= N; i++)
    {
        for(int j = a[i].s; j >= 0; j--)
            if(j + a[i].w <= 20000)
                dp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
    }

    LL ans = 0;
    for(int i = 0; i <= 20000; i++)
        ans = max(ans, dp[i]);
    cout << ans << '\n';

    return 0;
}
