#include <bits/stdc++.h>

using int64 = long long;

const int MAX_N = int(1e5) + 10;

int n, pos;
int id[MAX_N], in[MAX_N];
int64 b[MAX_N], l[MAX_N], u[MAX_N], X, all, val[MAX_N];

int main() {
	scanf("%d%lld", &n, &X);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld%lld", b + i, l + i, u + i);
		all -= b[i] * l[i];
		val[i] = (X - b[i]) * u[i] + b[i] * l[i];
	}

	for (int i = 1; i <= n; ++i) {
		id[i] = i;
	}
	std::sort(id + 1, id + n + 1, [&](const int &x, const int &y) { return val[x] > val[y]; });
	int64 sum = 0LL;
	for (int i = 1; i <= n; ++i) {
		sum += val[id[i]];
		if (sum + all >= 0) {
			pos = i - 1;
			sum -= val[id[i]];
			break;
		}
		in[id[i]] = true;
	}

	all = sum + all;
	int64 ans = (pos + 1) * X;
	for (int i = 1; i <= n; ++i) {
		int64 tmp = all;
		if (in[i]) {
			tmp -= val[i];
			tmp += val[id[pos + 1]];
		}

		int64 ql = 0LL, qr = X + 1;
		while (ql < qr) {
			int64 mid = (ql + qr) >> 1, s = 0LL;
			if (mid >= b[i])
				s = (mid - b[i]) * u[i];
			else
				s = (mid - b[i]) * l[i];
			if (tmp + b[i] * l[i] + s >= 0)
				qr = mid;
			else
				ql = mid + 1;
		}
		if (qr <= X) {
			ans = std::min(ans, pos * X + qr);
		}
	}

	std::cout << ans << std::endl;
}