import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias DF = Tuple!(size_t, "idx", long, "up");

long[10^^5] BS, LS, US, LOW_PS;
DF[10^^5] DFS;

void main()
{
    auto nx = readln.split.to!(int[]);
    auto N = nx[0];
    auto X = nx[1];

    long b_sum;
    foreach (i; 0..N) {
        auto blu = readln.split.to!(long[]);
        auto b = blu[0];
        auto l = blu[1];
        auto u = blu[2];
        BS[i] = b;
        LS[i] = l;
        US[i] = u;
        LOW_PS[i] = b * l;
        b_sum += b * l;
        DFS[i] = DF(i, X * u - b * u);
    }
    sort!"a.up > b.up"(DFS[0..N]);
    long a_sum;
    size_t i;
    long r;
    while (a_sum < b_sum) {
        auto d = DFS[i++];
        auto idx = d.idx;
        auto b = b_sum - LOW_PS[idx] + BS[idx] * US[idx];
        auto a = a_sum + X * US[idx];
        if (a < b) {
            b_sum = b;
            a_sum = a;
            r += X;
        } else {
            long rr = long.max;
            --i;
            for (; i < N; ++i) {
                idx = DFS[i].idx;
                auto r1 = (b_sum - a_sum + LS[idx] - 1) / LS[idx];
                if (r1 > X) r1 = long.max;
                auto r2 = (b_sum - LOW_PS[idx] + BS[idx] * US[idx] - a_sum + US[idx] - 1) / US[idx];
                if (r2 > X) r2 = long.max;

                rr = min(rr, r1);
                rr = min(rr, r2);
            }
            r += rr;
            break;
        }
    }
    writeln(r);
}