#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()

ll sum = 0, N, X;
vector<vector<ll>> A(100010);
vector<ll> Ru(100010, 0);

bool solve(ll a) {
	//a個選んだ時の結果
	ll p, q, cnt = 0, ans = 0;
	p = a / X;
	q = a % X;
	for (int i = 0;i < N;i++) {
		if (i > p)
			ans = Ru[p];
		else
			ans = Ru[p + 1] - A[i][0];

		if (A[i][1] > q) {
			//lowにする
			ans += q * A[i][2];
		}
		else {
			ans += q * A[i][3] - A[i][4];
		}
		cnt = max(cnt, ans);
	}
	return (cnt >= sum);
}

ll binary(ll ng, ll ok) {
	if (ng + 1 == ok)return ok;
	ll mid = (ng + ok) / 2;
	if (solve(mid)) {
		return binary(ng, mid);
	}
	else {
		return binary(mid, ok);
	}
}

int main() {
	ll b, l, u;
	cin >> N >> X;

	for (int i = 0;i < N;i++) {
		cin >> b >> l >> u;
		sum += b * l;
		A[i] = { u*X - (u - l)*b,b,l,u,(u - l)*b };
	}
	sort(all(A));
	reverse(all(A));
	for (int i = 1;i <= N;i++) {
		Ru[i] = Ru[i - 1] + A[i - 1][0];
	}
	cout << binary(-1, N*X) << endl;
}