#include <bits/stdc++.h>
using namespace std;
long long modinv(long long a) {
  long long b = ((int)1e6 + 3), u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= ((int)1e6 + 3);
  if (u < 0) u += ((int)1e6 + 3);
  return u;
}
int exp(int a, int b) {
  long long res = 1;
  long long sum = a;
  for (int i = 0; i < 30; ++i) {
    if ((1 << (i)) & b) {
      res = (res * sum) % ((int)1e6 + 3);
    }
    sum = (sum * sum) % ((int)1e6 + 3);
  }
  return res;
}
long long X;
class point {
 public:
  long long b;
  long long l;
  long long u;
};
bool operator<(const point& a, const point& b) {
  return a.b * a.l + (X - a.b) * a.u < b.b * b.l + (X - b.b) * b.u;
}
bool operator==(const point& a, const point& b) {
  return a.b * a.l + (X - a.b) * a.u == b.b * b.l + (X - b.b) * b.u;
}
bool operator>(const point& a, const point& b) {
  return a.b * a.l + (X - a.b) * a.u > b.b * b.l + (X - b.b) * b.u;
}
int N;
int main() {
  int N;
  cin >> N >> X;
  vector<point> line(N);
  long long sum = 0;
  for (int i = 0; i < (N); ++i) {
    cin >> line[i].b >> line[i].l >> line[i].u;
    sum += line[i].b * line[i].l;
  }
  sort((line).begin(), (line).end(), greater<point>());
  int place = 0;
  long long ans = 0;
  while (place < line.size() &&
         sum >= line[place].b * line[place].l +
                    (X - line[place].b) * line[place].u) {
    ans += X;
    sum -= line[place].b * line[place].l;
    sum += line[place].b * line[place].u;
    sum -= X * line[place].u;
    ++place;
  }
  if (sum > 0) {
    vector<point> bline;
    while (place < line.size()) {
      bline.push_back(line[place]);
      ++place;
    }
    long long nans = X;
    for (int i = 0; i < (bline.size()); ++i) {
      long long d = (sum - bline[i].b * bline[i].l + bline[i].b * bline[i].u +
                     bline[i].u - 1) /
                    bline[i].u;
      nans = min(nans, d);
    }
    for (int i = 0; i < (bline.size()); ++i) {
      long long d = (sum + bline[i].l - 1) / bline[i].l;
      nans = min(nans, d);
    }
    ans += nans;
  }
  cout << ans << endl;
  return 0;
}
