#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1010;
int f[N];
int v, w, s;
int n, m;
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> v >> w >> s;
for(int j = m; j >= v; j--)
for(int k = 0; k <= s && k * v <= j; k++)
f[j] = max(f[j], f[j-k*v] + k * w);
}
cout << f[m] << endl;
return 0;
}