类似最小乘积生成树那样。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <functional>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define eps 1e-10
#define inf 0x3f3f3f3f
#define LL long long
#define pii pair<int, int>
#define MP make_pair
#define md (ll + rr >> 1)
#define ls i << 1
#define rs ls | 1
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define N 100010
#define M 400020
struct point{
int x, y;
point(int x = 0, int y = 0) : x(x), y(y) {}
point operator - (const point &b) const {
return point(x - b.x, y - b.y);
}
point operator + (const point &b) const {
return point(x + b.x, y + b.y);
}
};
LL cross(point a, point b){
return 1LL * a.x * b.y - 1LL * a.y * b.x;
}
int n, m, sum;
int a[N], b[N], c[N];
point p[N];
LL dp[N], f[N], ans;
point gao(){
p[0] = point(0, 0), dp[0] = 0;
for(int i = 1; i <= sum; ++i) dp[i] = 1LL << 60;
for(int i = 1; i <= n; ++i){
for(int j = sum; j >= a[i]; --j){
if(dp[j] > dp[j-a[i]] + f[i]){
dp[j] = dp[j-a[i]] + f[i];
p[j] = p[j-a[i]] + point(b[i], c[i]);
}
}
}
int ret = m;
LL tot = 1LL * p[ret].x * p[ret].y;
for(int i = m; i <= sum; ++i) {
if(dp[i] < dp[ret] || dp[i] == dp[ret] && 1LL * p[i].x * p[i].y < tot)
ret = i, tot = 1LL * p[ret].x * p[ret].y;
}
ans = min(ans, tot);
return p[ret];
}
void solve(point A, point B){
for(int i = 1; i <= n; ++i)
f[i] = 1LL * c[i] * (B.x - A.x) + 1LL * b[i] * (A.y - B.y);
point C = gao();
if(cross(B - A, C - A) >= 0)
return ;
solve(A, C);
solve(C, B);
}
int main(){
while(scanf("%d%d", &n, &m) != EOF){
sum = 0;
for(int i = 1; i <= n; ++i){
scanf("%d%d%d", &a[i], &b[i], &c[i]);
sum += a[i];
}
ans = 1LL << 60;
for(int i = 1; i <= n; ++i)
f[i] = b[i];
point A = gao();
for(int i = 1; i <= n; ++i)
f[i] = c[i];
point B = gao();
solve(A, B);
cout << ans << endl;
}
return 0;
}