#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210000;

vector<tuple<ll, ll, ll>> vv;

int n;
ll x;

ll sma;

ll get(tuple<ll, ll, ll> a) {
	ll b, l, u;
	tie(b, l, u) = a;
	return b * l + (x - b) * u;
}

ll sm[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		ll b, l, u;
		cin >> b >> l >> u;
		sma += b * l;
		vv.emplace_back(b, l, u);
	}
	sort(ALL(vv), [] (tuple<ll, ll, ll> a, tuple<ll, ll, ll> b) -> bool {
				return get(a) > get(b);
			});
	for (int i = 0; i < n; ++i)
		sm[i + 1] = sm[i] + get(vv[i]);
	ll l = -1;
	ll r = x * n;
	while (r - l > 1) {
		ll m = (l + r) >> 1;
		ll ans = 0;
		int go = min(ll(n) - 1, m / x);
		for (int i = 0; i < n; ++i) {
			ll now = sm[go];
			if (i < go)
				now = sm[go + 1] - get(vv[i]);
			ll lf = m - go * x;
			ll b, l, u;
			tie(b, l, u) = vv[i];
			now += l * min(b, lf);
			if (lf > b)
				now += (lf - b) * u;
			ans = max(ans, now);
		}
		if (ans >= sma)
			r = m;
		else
			l = m;
	}
	cout << r << "\n";
	return 0;
}


