#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = (int)1e5 + 100;
ll b[maxN], l[maxN], u[maxN];
ll x;
ll pref[maxN];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> b[i] >> l[i] >> u[i];
    }
    ll S = 0;
    vector < pair < ll, int > > f;
    for (int i = 1; i <= n; i++) {
        S += l[i] * b[i];
        f.emplace_back(b[i] * (l[i] - u[i]) + x * u[i], i);
    }
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    pref[0] = 0;
    for (int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1] + f[i - 1].first;
    }
    ll best = 1e18;
    for (int who = 0; who < n; who++) {
        ll total = pref[who];
        int ind = f[who].second;
        if (total + b[ind] * l[ind] >= S) {
            int le = -2;
            int r = who - 1;
            // 0 .. mid
            while (r - le > 1) {
                int mid = (le + r) / 2;
                if (mid >= -1 && pref[mid + 1] + b[ind] * l[ind] >= S) r = mid;
                else le = mid;
            }
            int where = r;
            ll diff = S - pref[where + 1];
            ll pp = ((diff + l[ind] - 1) / (l[ind]));
            if (diff < 0) {
                best = min(best, (where + 1) * x);
                continue;
            }
            if (pp >= 0 && pp <= x) {
                best = min(best, (where + 1) * x + pp);
            }
            continue;
        }
        int le = who - 1;
        int r = n - 1;
        if (pref[r + 1] - pref[who + 1] + total + l[ind] * b[ind] < S) continue;
        while (r - le > 1) {
            int mid = (le + r) / 2;
            if (mid >= who && pref[mid + 1] - pref[who + 1] + total + l[ind] * b[ind] >= S) r = mid;
            else le = mid;
        }
        int where = r;
        ll diff = S - (pref[where + 1] - pref[who + 1] + total);
        ll pp = ((diff + l[ind] - 1) / (l[ind]));
        if (diff < 0) {
            best = min(best, (where) * x);
            continue;
        }
        if (pp >= 0 && pp <= x) {
            best = min(best, (where) * x + pp);
        }
    }
    for (int who = 0; who < n; who++) {
        ll total = pref[who];
        int ind = f[who].second;
        if (total + f[who].first >= S) {
            int le = -2;
            int r = who - 1;
            // 0 .. mid
            while (r - le > 1) {
                int mid = (le + r) / 2;
                if (mid >= -1 && pref[mid + 1] + f[who].first >= S) r = mid;
                else le = mid;
            }
            int where = r;
            ll diff = S - pref[where + 1] + b[ind] * u[ind] - b[ind] * l[ind];
            ll pp = ((diff + u[ind] - 1) / (u[ind]));
            // 0 .. where
            if (diff < 0) {
                best = min(best, (where + 1) * x + b[ind]);
                continue;
            }
            if (pp >= b[ind] && pp <= x) {
                best = min(best, (where + 1) * x + pp);
            }
            continue;
        }
        int le = who - 1;
        int r = n - 1;
        if (pref[r + 1] - pref[who + 1] + total + f[who].first < S) continue;
        while (r - le > 1) {
            int mid = (le + r) / 2;
            if (mid >= who && pref[mid + 1] - pref[who + 1] + total + f[who].first >= S) r = mid;
            else le = mid;
        }
        int where = r;
        ll diff = S - (pref[where + 1] - pref[who + 1] + total) + b[ind] * u[ind] - b[ind] * l[ind];
        ll pp = ((diff + u[ind] - 1) / (u[ind]));
        if (diff < 0) {
            best = min(best, (where) * x + b[ind]);
            continue;
        }
        if (pp >= b[ind] && pp <= x) {
            best = min(best, (where) * x + pp);
        }
    }
    cout << best;
    return 0;
}

Measured memory_bytes: 5104