#include <iostream>
#include <algorithm>

using namespace std;

struct block {
    int w, s, v;
    bool operator<(block a) const {
        return w + s < a.w + a.s;
    }
};

long long dp[20001]; // dp[i] is max value with weight of i

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    block blocks[n];
    for (int i = 0; i < n; i++) cin >> blocks[i].w >> blocks[i].s >> blocks[i].v;
    sort(blocks, blocks + n);
    for (int i = 0; i < n; i++) {
        for (int j = blocks[i].s; j >= 0; j--) dp[j + blocks[i].w] = max(dp[j + blocks[i].w], dp[j] + blocks[i].v);
    }
    long long ans = 0;
    for (int i = 0; i < 20001; i++) ans = max(ans, dp[i]);
    cout << ans;
    return 0;
}
