Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int64_t n, x;
    cin >> n >> x;
    bool all_zero = true;
    vector<tuple<int64_t,int64_t,int64_t>> tests;
    for(int i=0;i<n;i++){
        int b, l, u;
        cin >> b >> l >> u;
        if(b > 0) all_zero = false;
        tests.emplace_back(b,l,u);
    }

    if(all_zero){
        cout << 0 << endl;
        return 0;
    }
    sort(tests.begin(), tests.end(), [&x](const auto &l, const auto &r){
        return x*get<2>(l) - get<0>(l)*(get<2>(l) - get<1>(l)) > x*get<2>(r) - get<0>(r)*(get<2>(r) - get<1>(r));
    });
    vector<int64_t> sum_u, sum_l;
    sum_u.push_back(0);
    sum_l.push_back(0);
    for(auto t : tests){
        sum_u.push_back(sum_u.back() + (x-get<0>(t)) * get<2>(t));
        sum_l.push_back(sum_l.back() - get<0>(t) * get<1>(t));
    }

    int ok = n, ng = 0;
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        if(sum_u[mid] + sum_l[n] - sum_l[mid] >= 0) ok = mid;
        else ng = mid;
    }
    int manten = ok-1;
    ok = x; ng = 0;
    int64_t offset = sum_u[manten+1] + sum_l[n] - sum_l[manten+1];

    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        int best=10000000, best_idx;
        int64_t score = offset;
        for(int i=0;i<=manten;i++){
            int mul = (get<0>(tests[i])>mid?get<1>(tests[i]):get<2>(tests[i]));
            if(best > mul){
                best = mul;
                best_idx = i;
                score = offset - (x-get<0>(tests[i]))*get<2>(tests[i]) - mul*get<2>(tests[i]);
            }
        }
        for(int i=manten+1;i<n;i++){
            int mul = (get<0>(tests[i])>mid?get<1>(tests[i]):get<2>(tests[i]));
            if(best < mul){
                best = mul;
                best_idx = i;
                score = offset - (x-get<0>(tests[i]))*get<2>(tests[i]) - mul*get<2>(tests[i]);
            }
        }
        if(score>=0)ok=mid;
 else       ng = mid;
        continue;
        next_ok : ok = mid;
    }

    cout << manten*x + ok << endl;
    #include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int64_t n, x;
    cin >> n >> x;
    bool all_zero = true;
    vector<tuple<int64_t,int64_t,int64_t>> tests;
    for(int i=0;i<n;i++){
        int b, l, u;
        cin >> b >> l >> u;
        if(b > 0) all_zero = false;
        tests.emplace_back(b,l,u);
    }

    if(all_zero){
        cout << 0 << endl;
        return 0;
    }
    sort(tests.begin(), tests.end(), [&x](const auto &l, const auto &r){
        return x*get<2>(l) - get<0>(l)*(get<2>(l) - get<1>(l)) > x*get<2>(r) - get<0>(r)*(get<2>(r) - get<1>(r));
    });
    vector<int64_t> sum_u, sum_l;
    sum_u.push_back(0);
    sum_l.push_back(0);
    for(auto t : tests){
        sum_u.push_back(sum_u.back() + (x-get<0>(t)) * get<2>(t));
        sum_l.push_back(sum_l.back() - get<0>(t) * get<1>(t));
    }

    int ok = n, ng = 0;
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        if(sum_u[mid] + sum_l[n] - sum_l[mid] >= 0) ok = mid;
        else ng = mid;
    }
    int manten = ok-1;
    ok = x; ng = 0;
    int64_t offset = sum_u[manten+1] + sum_l[n] - sum_l[manten+1];

    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        int best=10000000, best_idx;
        int64_t score = offset;
        for(int i=0;i<=manten;i++){
            int mul = (get<0>(tests[i])>mid?get<1>(tests[i]):get<2>(tests[i]));
            if(best > mul){
                best = mul;
                best_idx = i;
                score = offset - (x-get<0>(tests[i]))*get<2>(tests[i]) - mul*get<2>(tests[i]);
            }
        }
        for(int i=manten+1;i<n;i++){
            int mul = (get<0>(tests[i])>mid?get<1>(tests[i]):get<2>(tests[i]));
            if(best < mul){
                best = mul;
                best_idx = i;
                score = offset - (x-get<0>(tests[i]))*get<2>(tests[i]) - mul*get<2>(tests[i]);
            }
        }
        if(score>=0)ok=mid;
 else       ng = mid;
        continue;
        next_ok : ok = mid;
    }

    cout << manten*x + ok << endl;
    
    return 0;
}
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:76:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   76 | int main(){
      |         ^~
a.cc:76:9: note: remove parentheses to default-initialize a variable
   76 | int main(){
      |         ^~
      |         --
a.cc:76:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:76:11: error: a function-definition is not allowed here before '{' token
   76 | int main(){
      |           ^