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_org;
    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_org += b * l;
        DFS[i] = DF(i, X * u - b * u);
    }
    sort!"a.up > b.up"(DFS[0..N]);
    
    long min_r, max_r = X * N;
    while (min_r + 1 != max_r) {
        auto mid_r = (min_r + max_r) / 2;
        bool can_win;
        auto len = mid_r / X;

        long a_sum, b_sum = b_sum_org;
        foreach (j; 0..len) {
            auto idx = DFS[j].idx;
            a_sum += X * US[idx];
            b_sum += BS[idx] * US[idx] - LOW_PS[idx];
        }

        foreach (i; 0..N) {
            auto idx = DFS[i].idx;
            auto as = a_sum;
            auto bs = b_sum;
            if (i < len) {
                auto ldx = DFS[len].idx;
                as = as - X * US[idx] + X * US[ldx];
                bs = bs - BS[idx] * US[idx] + LOW_PS[idx] - LOW_PS[ldx] + BS[ldx] * US[ldx];
            }
            auto ap = mid_r - X * len;
            if (ap < BS[idx]) {
                as += ap * LS[idx];
            } else {
                as += ap * US[idx];
                bs += BS[idx] * US[idx] - LOW_PS[idx];
            }
            
            if (as >= bs) {
                can_win = true;
                break;
            }
        }

        if (can_win) {
            max_r = mid_r;
        } else {
            min_r = mid_r;
        }
    }

    writeln(max_r);
}