#include <bits/stdc++.h>

const int N = 101010;

struct Node {
    long long l, r, b, w;
    inline bool operator < (const Node &o) const {
        return w > o.w;
    }
}a[N];

long long X, D, sum[N];
int n;

long long cal(long long x, long long y)
{
    if(x <= a[y].b)
        return x * a[y].l;
    return a[y].b * a[y].l + (x - a[y].b) * a[y].r;
}

inline bool check(long long k)
{
    long long ans = 0, r = k % X, t = k / X;
    if(t >= n)
        return sum[n];
    for(int i = 1; i <= n; i++)
	{
        if(i <= t)
			ans = std::max(ans, cal(r, i) + sum[t + 1] - a[i].w);
        else
            ans = std::max(ans, cal(r, i) + sum[t]);
    }
    return ans >= D;
}

int main()
{
    
    scanf("%d%lld", &n, &X);
    for(int i = 1; i <= n; i++)
	{
        scanf("%lld%lld%lld", &a[i].b, &a[i].l, &a[i].r);
        a[i].w = a[i].b * a[i].l + (X - a[i].b) * a[i].r;
        D += a[i].b * a[i].l;
    }
    std::sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + a[i].w;
    long long l = 0, r = 1e12;
    while(l < r)
	{
        long long mid = (l + r) >> 1;
        if(check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    printf("%lld\n", r);
    return 0;
}