#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,L;
struct exam {
	ll b,l,u;
	ll val() const {
		return L*u-b*u+b*l;
	}
	bool operator<(const exam &e)const {
		if(val()!=e.val())return val() > e.val();
		else return u<e.u;
	}
} A[MAXN];
ll psum[MAXN];
ll down,o;
// obv: get points for x exams, get full marks for x-1 exams, partial for 1 exam

int main()
{
	FAST
	cin>>n>>L;
	FOR(i,0,n){
		cin>>A[i].b>>A[i].l>>A[i].u; down-=A[i].b*A[i].l;
	} sort(A,A+n);o=down;if(down>=0){cout<<0<<'\n';return 0;}
	psum[0]=A[0].val();FOR(i,1,n)psum[i]=psum[i-1]+A[i].val();
	ll ans=1e9;
	ll co=0;
	while(co+1<n&&psum[co+1]-A[0].val()<-down)co++;
	ans=(co+2)*L;
	FOR(i,0,n){
		while(co>=0&&psum[co]-(co>=i?A[i].val():0ll)>=-down)--co;
		ll need=-down-psum[co]+(co>=i?A[i].val():0ll); ll took=(co+1)*L-(co>=i?L:0ll);
		if((L-A[i].b)*A[i].u+A[i].b*A[i].l<need)continue;
		if(need<=A[i].b*A[i].l){
			// stay as l
			ans=min(ans,took+(ll)ceill(need/(ld)A[i].l));assert((ll)ceill(need/(ld)A[i].l)<=A[i].b);
		} else {
			// go to u
			need-=A[i].b*A[i].l;
			need+=A[i].b*A[i].u;
			ans=min(ans,took+(ll)ceill(need/(ld)A[i].u));assert((ll)ceill(need/(ld)A[i].u)>=A[i].b&&(ll)ceill(need/(ld)A[i].u)<=L);
		}
		
	}
	FOR(i,0,n){
		if(ceill((-(down+A[i].b*A[i].l-A[i].b*A[i].u))/(ld)A[i].u)<=L)ans=min(ans,(ll)ceill((-(down+A[i].b*A[i].l-A[i].b*A[i].u))/(ld)A[i].u));
	}
	cout<<ans;
}



Measured memory_bytes: 5120