#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct block {
    ll w, s, v;

    block() : w(0), s(0), v(0) {}

    bool operator<(const block& other) const {
        return w + s > other.w + other.s;
    }
};

const int MAXS = 10000;

int N;
ll dp[MAXS + 1];
vector<block> b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    b.resize(N);
    for (int i = 0; i < N; i++)
        cin >> b[i].w >> b[i].s >> b[i].v;
    sort(b.begin(), b.end());
    ll result = 0;
    for (int i = N - 1; i >= 0; i--) {
        result = max(result, b[i].v + dp[b[i].s]);
        for (int j = MAXS; j >= 0; j--)
            if (b[i].w <= j)
                dp[j] = max(dp[j], b[i].v + dp[min(b[i].s, j - b[i].w)]);
    }
    cout << result << endl;
}
