#include #include #include #include #include #include #include #include #include #include #define mp make_pair #define pb push_back #define xx first #define yy second #define mod 1000000007ll using namespace std; vector > > a; int dp[3005]; bool cmp(pair > x, pair > y){ if (1.0 * x.xx / x.yy.xx - x.yy.yy != 1.0 * y.xx / y.yy.xx - y.yy.yy) return 1.0 * x.xx / x.yy.xx - x.yy.yy > 1.0 * y.xx / y.yy.xx - y.yy.yy; else x.yy.yy < y.yy.yy; } bool cmp1(pair > x, pair > y){ if (1.0 * x.yy.xx / x.yy.yy != 1.0 * y.yy.xx / y.yy.yy) return (1.0 * x.yy.xx / x.yy.yy > 1.0 * y.yy.xx / y.yy.yy); else x.yy.yy < y.yy.yy; } main() { int T, n , i, j, x, y, z, t; scanf("%d",&T); while (T--){ scanf("%d%d",&n,&t); memset(dp, 0, sizeof dp); a.clear(); for (i = 0; i < n; i++){ scanf("%d%d%d",&x, &y, &z); a.pb(mp(x, mp(y, z))); } sort(a.begin(), a.end(), cmp1); for (i = 0; i < n; i++){ x = a[i].xx; y = a[i].yy.xx; z = a[i].yy.yy; for (j = t; j >= z; j--) dp[j] = max(dp[j - 1], max(dp[j], dp[j - z] + x - j * y)); } int ma = dp[t]; for (i = 0; i <= t; i++) ma = max(dp[i], ma); printf("%d\n", dp[t]); } return 0; }