#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
int n;
struct Block{
	int w;
	int s;
	long long v;
}b[1005];
bool operator <(Block x,Block y){
	return x.w+x.s<y.w+y.s;
}
long long dp[100005];
int main(){
	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=b[i].s;j>=0;--j){
			dp[j+b[i].w]=max(dp[j+b[i].w],dp[j]+b[i].v);
		}
	}
	long long ans=0;
	for(int i=1;i<=100000;++i){
		ans=max(ans,dp[i]);
	}
	cout<<ans<<'\n';
	return 0;
}