#include <bits/stdc++.h>

#define rin(i,a,b) for(int i=(a);i<=(b);++i)
#define irin(i,a,b) for(int i=(a);i>=(b);--i)
#define trav(i,a) for(int i=head[a];i;i=e[i].nxt)
#define Size(a) (int)a.size()
#define pb push_back
#define mkpr std::make_pair
#define fi first
#define se second
#define lowbit(a) ((a)&(-(a)))
typedef long long LL;

using std::cerr;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=100005;

int n,fullmark;
LL B,sum[MAXN];

struct subj{
	int b,l,r;LL tot;
	inline friend bool operator < (subj x,subj y){
		return x.tot<y.tot;
	}
}s[MAXN];

bool check(LL mid){
	LL cnt=mid/fullmark,rem=mid-fullmark*cnt;
	if(!rem)return sum[n]-sum[n-cnt]>=B;
	rin(i,1,n){
		LL ext=0;
		if(i<=n-cnt)ext=sum[n]-sum[n-cnt];
		else ext=sum[n]-sum[n-cnt-1]-s[i].tot;
		if(rem<=s[i].b)if(rem*s[i].l+ext>=B)return true;
		if(rem>s[i].b)if(1ll*s[i].b*s[i].l+(rem-s[i].b)*s[i].r+ext>=B)return true;
	}
	return false;
}

int main(){
	n=read(),fullmark=read();
	rin(i,1,n){
		s[i].b=read();
		s[i].l=read();
		s[i].r=read();
		s[i].tot=1ll*s[i].b*s[i].l+1ll*(fullmark-s[i].b)*s[i].r;
		B+=1ll*s[i].b*s[i].l;
	}
	std::sort(s+1,s+n+1);
	rin(i,1,n)sum[i]=sum[i-1]+s[i].tot;
	LL l=0,r=1ll*fullmark*n,ans=0;
	while(l<=r){
		LL mid=((l+r)>>1);
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}