/* -*- coding: utf-8 -*- * * 2701.cc: No.2701 A cans -> B cans - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 5000; const int MAX_M = 5000; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N], bs[MAX_N], cs[MAX_N]; ll dp0[MAX_N][MAX_M + 1], dp1[MAX_M + 1], dp2[MAX_M + 1]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d%d%d", as + i, bs + i, cs + i); for (int i = 0; i < n; i++) for (int j = as[i]; j <= m; j++) { dp0[i][j] = (ll)bs[i] * cs[i] + dp0[i][j - as[i] + bs[i]]; dp1[j] = max(dp1[j], dp0[i][j]); } for (int j = 1; j <= m; j++) { for (int j1 = 1; j1 <= j; j1++) dp2[j] = max(dp2[j], dp1[j1] + dp2[j - j1]); printf("%lld\n", dp2[j]); } return 0; }