Language: C++

#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;
 
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;
 
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';
 
#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())
#define int long long
 
 
template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class S, class T> inline void chmax(S &a, T b){if(a < b) a = b;}
template <class S, class T> inline void chmin(S &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
  std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}
 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
 
class Problem_Solver{
private:
    using LLi = long long int;
    using datum = std::tuple<int, LLi, LLi>;
    const int n, X;
    lli sum_lost_score;
    std::vector<datum> D;
    // S[i] := i個まで全て選んだ時の増加得点
    std::vector<LLi> S;
public:
    Problem_Solver(int nn, int XX):n(nn),X(XX){
        D.resize(n); S.resize(n);
    };
    // 入力を行う
    void input(){
        sum_lost_score = 0;
        REP(i, n){
            // 得点は -bl => uX - ubに変化
            int b, l, u; scanf("%d%d%d", &b, &l, &u);
            D[i] = {b, l, u};
            sum_lost_score += static_cast<LLi>(b) * l;
        }
        // ついでにソート
        std::sort(D.begin(), D.end(), [&](datum a, datum b){
            int aB, bB; lli aL, aU, bL, bU;
            std::tie(aB, aL, aU) = a;
            std::tie(bB, bL, bU) = b;
            // 増加得点は uX - b(u-l)
            return aU*X-aB*(aU-aL) > bU*X-bB*(bU-bL);
        });
    }
    // 前処理
    void previous(){
        S[0] = 0;
        REP(i, n){
            int b; lli l, u;
            std::tie(b, l, u) = D[i];
            // 増加得点は uX - b(u-l)
            S[i+1] = S[i] + u * X - b * (u - l);
        }
    }
    // k個で可能か判定
    bool possible(lli k)const{
        int idx = k / X; int amari = k - idx * X;
        if(S[idx] >= sum_lost_score) return true;
        lli need = sum_lost_score - S[idx];
        for(; idx < n; ++idx){
            int b; lli l, u;
            std::tie(b, l, u) = D[idx];
            // 余り個使ってできる増加得点
            lli MakeScore_WithAmari = (amari > b) ? u * amari - b * (u-l) : l * amari;
            //std::max(u * amari - b * (u-l), l * amari);
            if(MakeScore_WithAmari >= need){
                return true;
            }
        }
        return false;
    }
    // 答えを見つける
    LLi findAns()const{
        lli ng = -1, ok = n; ok *= X;
        while(ok - ng > 1){
            lli m = (ng + ok) / 2;
            if(possible(m)) ok = m;
            else ng = m;
        }
        return ok;
    }
    // 出力
    void solve(){
        this->previous();
        printf("%lld\n", this->findAns());
    }
};
 
 
int main(void){
    int n, X; scanf("%d%d", &n, &X);
    Problem_Solver AtCoder(n, X);
    AtCoder.input();
    AtCoder.solve();
    return 0;
}

Compiler output:
a.cc:46:13: error: 'long long long' is too long for GCC
   46 | #define int long long
      |             ^~~~
a.cc:60:18: note: in expansion of macro 'int'
   60 | inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
      |                  ^~~
a.cc:46:18: error: 'long long long' is too long for GCC
   46 | #define int long long
      |                  ^~~~
a.cc:60:18: note: in expansion of macro 'int'
   60 | inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
      |                  ^~~
a.cc:46:13: error: 'long long long' is too long for GCC
   46 | #define int long long
      |             ^~~~
a.cc:75:27: note: in expansion of macro 'int'
   75 |     using LLi = long long int;
      |                           ^~~
a.cc:46:18: error: 'long long long' is too long for GCC
   46 | #define int long long
      |                  ^~~~
a.cc:75:27: note: in expansion of macro 'int'
   75 |     using LLi = long long int;
      |                           ^~~
cc1plus: error: '::main' must return 'int'