n, v = map(int, input().split())
f = [0 for _ in range(v+1)]
goods = []
# 将同种物品进行拆分
for i in range(n):
t, j, s = map(int, input().split())
k = 1
while k <= s:
goods.append([t*k, j*k])
s -= k
k = k * 2
if s > 0:
goods.append([t*s, j*s])
# 转化为0-1背包问题
m = len(goods)
for i in range(m):
for j in range(v, goods[i][0]-1, -1):
f[j] = max(f[j], f[j - goods[i][0]] + goods[i][1])
print(f[-1])