#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, x;
int b[N], l[N], u[N];
long long cal(int id, int a) {
    if (a < b[id]) return 1LL * l[id] * (a - b[id]);
    else return 1LL * u[id] * (a - b[id]);
}
int id[N];
bool cmp(int a, int b) {
    return cal(a, x) - cal(a, 0) > cal(b, x) - cal(b, 0);
}
bool chk(long long t) {
    long long sum = 0;
    for (int i = 0; i < n; ++ i) sum += cal(i, 0);
    int tot = t / x;
    for (int i = 0; i < tot; ++ i) sum += cal(id[i], x) - cal(id[i], 0);
    if (tot == n) return sum >= 0;
    int rem = t % x;
    long long mx = 0;
    for (int i = 0; i < n; ++ i) {
        if (i < tot) mx = max(mx, cal(id[i], rem) - cal(id[i], x) + cal(id[tot], x) - cal(id[tot], 0));
        else mx = max(mx, cal(id[i], rem) - cal(id[i], 0));
    }
    // cerr << t << " " << sum << " " << mx << endl;
    return sum + mx >= 0;
}
int main() {
    cin >> n >> x;
    for (int i = 0; i < n; ++ i) {
        cin >> b[i] >> l[i] >> u[i];
        id[i] = i;
    }
    sort(id, id + n, cmp);
    long long lb = 0, rb = 1LL * n * x;
    while (lb < rb) {
        long long md = lb + (rb - lb) / 2;
        if (chk(md)) rb = md;
        else lb = md + 1;
    }
    cout << lb << endl;
    return 0;
}