/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author izban
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;

#ifdef HOME
#define db(x) { cerr << #x << " = " << x << endl; }
#define db2(x, y) { cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl; }
#define db3(x, y, z) { cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl; }
#define dbv(a) { cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl; }
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

#define sz(a)  (int)(a).size()
#define all(a) (a).begin(),a.end()
#define pw(x)  (1LL << (x))


struct my_heap {
    multiset<ll> s1;
    multiset<ll> s2; // s2 <= s1
    ll sum1;

    my_heap() : sum1(0) {}

    void add(ll x) {
        if (s1.empty() || x >= *s1.begin()) {
            s1.insert(x);
            sum1 += x;
        } else s2.insert(x);
    }

    ll get(int k) {
        while (s1.size() < k) {
            ll x = *s2.rbegin();
            auto it = s2.end();
            s2.erase(--it);
            s1.insert(x);
            sum1 += x;
        }
        while (s1.size() > k) {
            ll x = *s1.begin();
            s1.erase(s1.begin());
            sum1 -= x;
            s2.insert(x);
        }
        return sum1;
    }

    void del(ll x) {
        if (s1.find(x) != s1.end()) s1.erase(s1.find(x)), sum1 -= x;
        else if (s2.find(x) != s2.end()) s2.erase(s2.find(x));
        else
            assert(0);
    }

    int size() const {
        return s1.size() + s2.size();
    }
};

class C {
public:
    void solve(std::istream &in, std::ostream &out) {
        ios_base::sync_with_stdio(0);
        in.tie(0);

        int n, x;
        in >> n >> x;
        vector<int> b(n), l(n), u(n);
        for (int i = 0; i < n; i++) {
            in >> b[i] >> l[i] >> u[i];
        }

        /*struct govno {
            ll y0;
//            vector<ll> len;
//            vector<ll> delta;
            vector<pair<ll, ll>> a;

            govno() {}
            govno(int b, int l, int u) {
                y0 = -1LL * b * l;
                len.push_back(b);
                delta.push_back(l);
                len.push_back(x - b);
                delta.push_back(l);
            }
        };*/

        my_heap h;
        ll cur = 0;
        vector<ll> mx(n);
        for (int i = 0; i < n; i++) {
            cur -= 1LL * b[i] * l[i];
            mx[i] = 1LL * (x - b[i]) * u[i] + 1LL * b[i] * l[i];
            h.add(mx[i]);
        }

        ll L = -1, R = 1LL * n * x;
        while (R - L > 1) {
            ll M = (L + R) >> 1;

            bool f = 0;
            for (int i = 0; i < n; i++) {
                h.del(mx[i]);
                ll left = M % x;
                ll now = cur + h.get(M / x) + max(1LL * (left - b[i]) * l[i], 1LL * (left - b[i]) * u[i]) +
                         1LL * b[i] * l[i];
                h.add(mx[i]);
                if (now >= 0) {
                    f = 1;
                    break;
                }
            }
            if (f) R = M;
            else L = M;
        }
        out << R << endl;
    }
};


int main() {
    C solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 9052