#include<bits/stdc++.h>
#define ll long long
#define N 100010
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
struct Info{ll b,l,r,mi,ma;}a[N];
ll ansn,su,n,X,s1[N],ans;
bool comp(const Info &a,const Info &b){return a.ma-a.mi>b.ma-b.mi;}
ll ch(ll x,ll y){return x/y+(x%y!=0);}
ll get(ll x,ll y){
	if (a[y].mi<=x){
		return ch(-x,a[y].l);
	}else{
		return a[y].b+ch(-x+a[y].mi,a[y].r);
	}	
}
int main(){
	read(n);read(X);
	for (int i=1;i<=n;i++){
		read(a[i].b);read(a[i].l);read(a[i].r);
		a[i].mi=-a[i].b*a[i].l;
		a[i].ma=(X-a[i].b)*a[i].r;
	}
	sort(a+1,a+n+1,comp);
	for (int i=1;i<=n;i++)ansn+=a[i].mi;
	for (int i=1;i<=n;i++)s1[i]=s1[i-1]+a[i].ma-a[i].mi;
	for (int i=1;i<=n;i++)if (ansn+s1[i]>=0){su=i-1;break;}
	ans=X;
	for (int i=1;i<=n;i++){
		ll p;
		if (i>su)p=ansn+s1[su];else p=ansn+s1[su+1]-a[i].ma+a[i].mi;
		ans=min(ans,get(p,i));
	}
	cout<<ans+su*X<<endl;
	return 0;
}