#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,X; cin >> N >> X;
	struct test{
		ll b,l,u,c;
		test(ll b,ll l,ll u,ll c):b(b),l(l),u(u),c(c){}
		bool operator<(const test &t) const{
			return c>t.c;
		}
	};
	vector<test> ts;
	ll sum=0;
	for (int i=0;i<N;++i){
		ll b,l,u; cin >> b >> l >> u;
		ts.emplace_back(b,l,u,u*(X-b)+l*b);
		sum+=l*b;
	}
	sort(ts.begin(),ts.end());
	ll lb=-1,ub=N*X;
	while(ub-lb>1){
		ll mid=(ub+lb)>>1LL;
		ll cnt=0;
        for (int i=0;i<mid/X;++i) cnt+=ts[i].c;
        int ok=0;
        for (int i=0;i<N;++i){
            test t=ts[i];
            ll cnt0=cnt;
            if (i<mid/X) cnt0+=ts[mid/X].c-t.c;
            if (mid%X<t.b) cnt0+=t.l*(mid%X);
			else cnt0+=t.u*(mid%X-t.b)+t.l*t.b;
            if (cnt0>=sum) ok=1;
        }
		(ok?ub:lb)=mid;
	}
	cout << ub << '\n';
}