include [HTML_REMOVED]
using namespace std;
int n, m;
int f[20002], q[20002], g[20002];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i) {
int v, w, s;
cin >> v >> w >> s;
memcpy(g, f, sizeof(f));
if (s < 0) {
for (int j = m;j >= v;j–) {
f[j] = max( f[j],f[j-v] + w );
}
}
if (s == 0) {
for (int j = v;j <= m;j) {
f[j] = max(f[j], f[j - v] + w);
}
}
if (s > 0) {
for (int j = 0;j < v;j) {
int hh = 0, tt = -1;
for (int k = j;k <= m;k += v) {
if (hh <= tt && (k - q[hh]) / v > s)
hh;
if (hh <= tt)
f[k] = max(f[k], g[q[hh]] + (k - q[hh]) / vw);
if (hh <= tt&&g[q[tt]] - (q[tt] - j) / vw <= g[k] - (k - j) / v*w)
tt–;
q[++tt] = k;
}
}
}
}
cout << f[m] << endl;
}