#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long x;
  cin >> n >> x;
  vector<long long> b(n), l(n), u(n);
  long long loss = 0;
  for (int i = 0; i < n; i++) {
    cin >> b[i] >> l[i] >> u[i];
    loss += b[i] * l[i];
  }
  vector<long long> value(n);
  for (int i = 0; i < n; i++) {
    value[i] = x * u[i] - b[i] * (u[i] - l[i]);
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    return value[i] > value[j];
  });
  vector<long long> pref(n + 1);
  for (int i = 0; i < n; i++) {
    pref[i + 1] = pref[i] + value[order[i]];
  }
  long long ans = (long long) 9e18;
  for (int it = 0; it < n; it++) {
    int i = order[it];
    for (long long coeff : {l[i], u[i]}) {
      int low = 0, high = n;
      while (low <= high) {
        int mid = (low + high) >> 1;
        long long cur = loss;
        if (coeff == u[i]) {
          cur += b[i] * (u[i] - l[i]);
        }
        long long can_get = pref[mid];
        long long vals = mid;
        if (it < mid) {
          can_get -= value[i];
          vals -= 1;
        }
        can_get += x * coeff;
        if (can_get >= cur) {
          can_get -= x * coeff;
          long long need = 0;
          if (can_get < cur) {
            need = (cur - can_get + coeff - 1) / coeff;
          }
          ans = min(ans, vals * x + need);
        }
        if (low == high) {
          break;
        }
        if (can_get >= cur) {
          high = mid;
        } else {
          low = mid + 1;
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <functional>
using namespace std;
using T=tuple<int64_t,int>;

int main(){
    int64_t N,X;
    cin>>N>>X;
    vector<int64_t> B(N),L(N),U(N);
    for(int i=0;i<N;i++){
        cin>>B[i]>>L[i]>>U[i];
    }
    vector<T> V;
    for(int i=0;i<N;i++){
        V.emplace_back(U[i]*(X-B[i])+L[i]*B[i],i);
    }
    sort(V.begin(), V.end(),greater<T>());
    function<bool(int64_t)> test = [&](int64_t sum){
        int64_t total=0;
        for(int i=0;i<N;i++){
            int idx;
            tie(ignore,idx)=V[i];
            if(i<(sum+X-1)/X){
                total+=U[idx]*(X-B[idx]);
            }else{
                total+=-L[idx]*B[idx];
            }
        }
        if(sum%X==0){
            return total>=0;
        }
        int64_t maximum=-10000000000000;
        for(int i=0;i<N;i++){
            int idx;
            tie(ignore,idx)=V[i];
            int64_t diff = max(U[idx]*(sum%X-B[idx]),L[idx]*(sum%X-B[idx]));
            if(i<(sum+X-1)/X){
                maximum = max(maximum, total-U[idx]*(X-B[idx])+diff);
            }else{
                int edge = get<1>(V[(sum+X-1)/X-1]);
                maximum = max(maximum, total-U[edge]*(X-B[edge])-L[edge]*B[edge]+L[idx]*B[idx]+diff);
            }
        }
        // cout<<sum<<' '<<maximum<<' '<<total<<endl;
        return maximum>=0;
    };
    int64_t lb=0,ub=X*N;
    while(ub-lb>1){
        int64_t mid=(lb+ub)/2;
        if(test(mid)){
            ub=mid;
        }else{
            lb=mid;
        }
    }
    if(lb==0&&test(lb)){
        cout<<lb<<endl;
    }else{
        cout<<ub<<endl;
    }
    return 0;
}