#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

struct block{
	llint w, s, v;
	block(){};
	bool operator<(const block &obj)const{
		return w+s < obj.w+obj.s;
	}
};

llint n;
block b[1005];
llint dp[1005][20005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> b[i].w >> b[i].s >> b[i].v;
	}
	sort(b+1, b+n+1);
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 20005; j++){
			dp[i][j] = dp[i-1][j];
			if(j-b[i].w >= 0 && b[i].s >= j-b[i].w){
				dp[i][j] = max(dp[i][j], dp[i-1][j-b[i].w] + b[i].v);
			}
		}
	}
	
	llint ans = 0;
	for(int i = 0; i < 20005; i++) ans = max(ans, dp[n][i]);
	cout << ans << endl;
	
	return 0;
}