#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int n,t;
int w,v,m;
int f[40005];
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main()
{
ios::sync_with_stdio(0);
freopen("treasure.in","r",stdin);
freopen("treasure.out","w",stdout);
n=read();t=read();
for(int i = 1 ; i <= n ; i ++ )
{
v=read();
w=read();
m=read();
for(int j = t ; j >= w ; j -- )
{
for(int k = 1 ; k <= m && k*w <= j ; k ++ )
f[j] = max(f[j],f[j-k*w]+v*k);
}
}
cout<<f[t];
return 0;
}