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

struct st{
    ll b,l,u;
};
std::vector<st> sts(100010);

bool comp(const st &light,const st &r){
    return light.u*x-r.u*x-light.b*light.u+r.b*r.u+light.b*light.l-r.b*r.l > 0;
}

int main() {
    
    std::cin >> n>>x;
    
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> sts[i].b>>sts[i].l>>sts[i].u;
        sum += sts[i].b*sts[i].l;
    }
    sort(sts.begin(),sts.end(),comp);
    
    ll now = -1;
    
    vector<ll> d(n);
    vector<ll> d_sum(n);
    // std::cout << sum<<" sum" << std::endl;
    for (int i = 0; i < n; i++) {
        d[i] = (x-sts[i].b)*sts[i].u+sts[i].b*sts[i].l;

        if(i>0){
            d_sum[i] = d_sum[i-1]+d[i];
        }else{
            d_sum[i] = d[i];
        }
        // std::cout << i<<" "<<d_sum[i] << std::endl;
        if(d_sum[i] >= sum && now == -1){
            now = i;
        }
    }
    ll result = 1e10;
     // 中途半端になるやつ
    for (int i = 0; i < n; i++) {
        ll now_sum = sum;
        if( i <= now ){
            now_sum -= d_sum[now] - d[i];
        }else if(now>0){
            now_sum -= d_sum[now-1];
        }
        
        ll y = (now_sum+sts[i].b*sts[i].u-sts[i].b*sts[i].l +sts[i].u-1 )/sts[i].u;
        y = min(y,(now_sum+sts[i].l-1)/sts[i].l);

        if(0 <= y && y <= x){
            result = min(result,now*x+y);
        }
    }
    
    std::cout << result << std::endl;
}
