#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;
int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> b(n),l(n),u(n);
    vector<pair<ll,ll>> a(n);
    ll uu=0;
    rep(i,n){
        cin >> b.at(i) >> l.at(i) >> u.at(i);
        a.at(i).first=u.at(i)*(x-b.at(i))+l.at(i)*b.at(i);
        a.at(i).second=i;
        uu+=l.at(i)*b.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll sum=0,v;
    rep(i,n){
        sum+=a.at(i).first;
        if (sum>uu) {sum-=a.at(i).first;v=i;break;}
        if (sum==uu) {cout << (i+1)*x << endl;return 0;}
    }
    ll ans=INF;
    rep(i,n){
        ll y=sum;
        int p=a.at(i).second;
        if (i<v) y=sum-a.at(i).first+a.at(v).first;
        ll t=uu-y+(u.at(p)-l.at(p))*b.at(p);
        ll o=t/u.at(p);
        if (t%u.at(p)!=0) o++;
        ans=min(ans,v*x+o);
        t=uu-y;
        o=t/l.at(p);
        if (t%l.at(p)!=0) o++;
        ans=min(ans,v*x+o);
    }
    cout << ans << endl;
}
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <array>

using namespace std;

void re(int& x);

template<class T, class... Ts> void re(T& t, Ts&... ts);

void pr(long long x);

void pr(const char *x);

void ps();
template<class T, class... Ts> void ps(const T& t, const Ts&... ts);

#ifdef FFDBG

#else
#define dbg(x...) dsfdsfsdfasd
#endif

typedef long long ll;

#define rep(i, a, b) for(int i = a; i < (b); ++i)

int n, x;
long long tgt = 0;

struct ex {
    int l, r, b;
} exam[110000];

long long score(const ex& a, long long h) {
    long long sc = a.l * 1ll * min(h, (ll)a.b);
    sc += a.r * 1ll * max(0LL, h-a.b);
    return sc;
}

bool check(long long hrs) {
    int full = hrs / x;
    int rem = hrs % x; 

    long long sc = 0;
    rep(i,0,full) sc += score(exam[i], x);
    long long best = sc;

    rep(i,full,n) best = max(best, sc + score(exam[i], rem));
    
    if (full < n) {
        sc += score(exam[full], x);
        rep(i,0,full) best = max(best, sc - score(exam[i], x) + score(exam[i],rem));
    }
    
    return best >= tgt;
}

void solve()
{
    re(n,x);
    rep(i,0,n) re(exam[i].b, exam[i].l, exam[i].r);

    rep(i,0,n) tgt += exam[i].l * 1ll * exam[i].b;

    sort(exam, exam+n, [](const ex& a, const ex& b) {
        return score(a,x) > score(b,x);
    });

    long long st = 0, ed = n*1ll*x;
    while (st < ed) {
        long long md = (st+ed)/2;
        if (check(md)) ed = md;
        else st = md+1;
    } 

    ps(st);
}

int main() {

    solve();
}

void re(int& x) { scanf("%d", &x); }

template<class T, class... Ts> void re(T& t, Ts&... ts) { 
    re(t); re(ts...); 
}

void pr(long long x) { printf("%lld", x); }

void pr(const char *x) { printf("%s", x); }

void ps() { pr("\n"); }
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) { 
    pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); 
}

