#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int q[200010];
int dp[2][200010];
int t = 0;
for (int i = 0; i < n; ++i) {
int c, w, s;
cin >> w >> c >> s;
t ^= 1;
for (int j = 0; j < c; ++j) {
int hh = 0, tt = -1;
for (int k = j; k <= m; k += c) {
if (hh <= tt && k - s * c > q[hh]) ++hh;
if (hh <= tt) dp[t][k] = max(dp[t^1][k], dp[t^1][q[hh]] + (k - q[hh]) / c * w);
while (hh <= tt && dp[t^1][q[tt]] + (k - q[tt]) / c * w <= dp[t ^ 1][k]) --tt;
q[++tt] = k;
}
}
}
cout << dp[t][m] << endl;
return 0;
}