#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 100010;

typedef long long ll;

ll Ans = 1e18;

int n, X;
ll b[maxn], l[maxn], u[maxn], in[maxn];
ll sum[maxn], val[maxn];

bool cmp(int x, int y) {
	return val[x] > val[y];
}

int main() {
	scanf("%d%d", &n, &X);
	for (int i = 1; i <= n; i++) scanf("%lld%lld%lld", &b[i], &l[i], &u[i]);
	for (int i = 1; i <= n; i++) {
		in[i] = i;
		val[i] = 1LL*(X-b[i])*u[i]+1LL*l[i]*b[i];
	}
	sort(in+1, in+n+1, cmp);
	ll s = 0;
	for (int i = 1; i <= n; i++) s += -1LL*b[i]*l[i];
	for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + val[in[i]];
	if (s >= 0) {
		puts("0");
		return 0;
	}
	for (int t = 1; t <= n; t++) {
		int i = in[t];
		ll cs = s - min(-X*l[i], -X*u[i]+b[i]*u[i]-b[i]*l[i]);
		int L = 0, R = n, ans = -1;
		while (L <= R) {
			int mid = (L + R) >> 1;
			ll v = sum[mid];
			if (mid >= t) v -= val[i];
			if (v+cs >= 0) {
				ans = mid;
				R = mid-1;
			} else L = mid+1;
		}
		ll cnt = ans;
		if (cnt >= t) -- cnt;
		ll v = sum[ans];
		if (ans >= t) v -= val[i];
		if (v+s >= 0) {
			Ans = min(Ans, 1ll*X*cnt);
			continue;
		}
		//v+s + x*l[i] >= 0
		//x >= -v-s/l[i]
		if ((-v-s+l[i]-1)/l[i] <= X) {
			Ans = min(Ans, 1ll*X*cnt+1ll*(-v-s+l[i]-1)/l[i]);
		}
		//v+s + x*u[i] + b[i]*l[i] - u[i]*l[i] >= 0
		ll tmp = -v-s-b[i]*l[i]+u[i]*b[i];
		if ((tmp+u[i]-1)/u[i] <= X) {
			Ans = min(Ans, 1ll*X*cnt+1ll*(tmp+u[i]-1)/u[i]);
		}
	}
	printf("%lld\n", Ans);
	return 0;
}