#include using namespace std; using ll = long long; int N, M; ll A[5050], B[5050], C[5050]; struct dat{ ll mx1, id1, mx2, id2; void apply(ll m, int i){ if(id1 == i){ mx1 = max(mx1, m); }else if(id2 == i){ mx2 = max(mx2, m); if(mx1 < mx2){ swap(mx1, mx2); swap(id1, id2); } }else if(mx1 < m){ mx1 = m, id1 = i; }else if(mx2 < m){ mx2 = m, id2 = i; } } }; dat dp[5050], ndp[5050]; template void Fill(A (&arr)[N], const T &val){ fill((T*)arr, (T*)(arr + N), val); } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for(int i = 0;i < N;i++)cin >> A[i] >> B[i] >> C[i]; Fill(dp, dat({0, -1, 0, -1})); Fill(ndp, dat({0, -1, 0, -1})); for(int i = 0;i < N;i++){ for(int j = 0;j <= M;j++){ { ndp[j].apply(dp[j].mx1, dp[j].id1); int nm = j + A[i] - (ndp[j].id1 == i) * B[i]; if(nm <= M){ ndp[nm].apply(ndp[j].mx1 + B[i] * C[i], i); } } { ndp[j].apply(dp[j].mx2, dp[j].id2); int nm = j + A[i] - (ndp[j].id2 == i) * B[i]; if(nm <= M){ ndp[nm].apply(ndp[j].mx2 + B[i] * C[i], i); } } } swap(dp, ndp); Fill(ndp, dat({0, -1, 0, -1})); } for(int i = 1;i <= M;i++){ cout << dp[i].mx1 << "\n"; } return 0; }