#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int lim = 20000;
int main() {
	int N;
	cin >> N;
	vector<int> W(N), S(N), V(N);
	for (int i = 0; i < N; ++i) {
		cin >> W[i] >> S[i] >> V[i];
	}
	vector<int> p(N);
	for (int i = 0; i < N; ++i) {
		p[i] = i;
	}
	sort(p.begin(), p.end(), [&](int i, int j) { return W[i] + S[i] < W[j] + S[j]; });
	vector<long long> dp(lim + 1);
	for (int i = 0; i < N; ++i) {
		for (int j = S[p[i]]; j >= 0; --j) {
			dp[j + W[p[i]]] = max(dp[j + W[p[i]]], dp[j] + V[p[i]]);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << '\n';
	return 0;
}