#include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,B; cin >> N >> B; vector dp(B+1); while(N--){ int p,c,s,d; cin >> p >> c >> s >> d; for(int t=1; t<=c; t++){ int back = (s-d*(t-2))*(t-1); int now = (s-d*(t-1))*t; now -= back; for(int i=B; i>=p; i--) dp.at(i) = max(dp.at(i),dp.at(i-p)+now); } } cout << dp.at(B) << endl; }