#include using namespace std; const int N = 1010, M = 20010; int n, m; int f[M], g[M]; int q[M]; int v, w, s; // 一维写法 int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { memcpy(g, f, sizeof g); cin >> v >> w >> s; for (int j = 0; j < v; j++) { int hh = 0, tt = -1; for (int k = j; k <= m; k += v) { if (hh <= tt && q[hh] < k - s * v) hh++; while (hh <= tt && g[k] >= g[q[tt]] + (k - q[tt]) / v * w) tt--; q[++tt] = k; f[k] = max(g[k], g[q[hh]] + (k - q[hh]) / v * w); } } } printf("%d\n", f[m]); return 0; }