#include<bits/stdc++.h>
using namespace std;
#define nn 1008
#define ll long long
#define pii pair<int,int>
int n;ll w[nn],s[nn],v[nn],f[20008],id[nn];
bool cmp(int x,int y)
{
	return s[x]+w[x]>s[y]+w[y];
}
ll ans=0;
void upd(ll &x,ll y)
{
	ans=max(ans,y);
	x=max(x,y);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>w[i]>>s[i]>>v[i],id[i]=i;
	sort(id+1,id+n+1,cmp);
	for(int di=1;di<=n;di++)
	{
		int i=id[di];
		for(int j=0;j<20004;j++)
		{
			if(j>=w[i])
				upd(f[min(j-w[i],s[i])],f[j]+v[i]);
		}
	}
	cout<<ans;
    return 0;
}