#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 7;

int n, x;

struct node {
  int b, l, u;
  ll sorce;
  friend bool operator < (const node& x, const node& y) {
    //if (x.sorce == y.sorce) return 1;
    return x.sorce > y.sorce;
  }
} a[maxn];

ll check(ll t) {
  ll tim = t / x;
  ll res = t - tim * x;
  ll sum = 0;
  for (int i = 1; i <= tim; i++) {
    sum += a[i].sorce;
  }
  ll ans = 0;
  //ans = sum;
  for (int i = 1; i <= n; i++) {
    ll now = 0;
    if (res <= a[i].b) 
      now = res * a[i].l;
    else 
      now = (long long)a[i].b * a[i].l + (long long)(res - a[i].b) * a[i].u;
    if (i <= tim) ans = max(ans, sum - a[i].sorce + now + a[tim + 1].sorce);
    else ans = max(ans, sum + now);
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  //cin.tie(0);
  //cout.tie(0);
  cin >> n >> x;
  ll goal = 0, maxx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].b >> a[i].l >> a[i].u;
    goal += (long long)a[i].b * a[i].l;
    a[i].sorce =(long long )a[i].b * a[i].l + (long long) a[i].u * (x - a[i].b);
  }
  sort(a + 1, a + n + 1);
  ll l = 0, r = (long long)n * x;
  while (l < r) {
    ll mid = (l + r) / 2;
    if (check(mid) >= goal) r = mid;
    else l = mid + 1;
  }
  cout << r << endl;
}