#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n;
long long X, D;

struct Node{
	long long x, l, r, num;
	bool operator <(const Node &b) const{
		return num > b.num;
	}
}node[maxn];
long long sum[maxn];

bool check(long long x) {
	int d = x / X, o = x % X;
	long long now = 0;
	for (int i = 1; i <= n; ++i) {
		if(o < node[i].x) now = (o - node[i].x) * node[i].l;
		else now = (o - node[i].x) * node[i].r;
		if(i <= d) now += sum[d + 1] - node[i].num + node[i].x * node[i].l;
		else now += sum[d] + node[i].x * node[i].l;
		if(now >= D) return 1;
	}
	return 0;
}

int main() {
	scanf("%d%lld", &n, &X);
	long long l = -1, r = 0, mid;
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld%lld", &node[i].x, &node[i].l, &node[i].r);
		node[i].num = node[i].x * node[i].l;
		D += node[i].num;
		node[i].num += (X - node[i].x) * node[i].r;
		r += node[i].x;
	}
	sort(node + 1, node + n + 1);
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + node[i].num;
	while(l < r - 1) {
		mid = (l + r) >> 1;
		if(check(mid)) r = mid;
		else l = mid;
	}
	printf("%lld\n", r);
	return 0;
}