Language: C++


#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std
#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,X;cin>>N>>X;
  vector<tuple<ll,ll,ll,ll> > tmp(N);
  for(ll i=0;i<N;i++){
    ll b,l,u;
    cin>>b>>l>>u;
    tmp[i]=make_tuple(u*(X-b)+l*b,b,l,u);
  }
  sort(tmp.begin(),tmp.end());
  ll low=-1,high=X*N+1;
  while(high-low>1){
    ll mid=(high+low)/2;
    ll q = mid/X;
    ll r = mid-q*X;
    ll sum1=0,sum2=0;
    bool isok=false;
    for(ll i=0;i<N;i++){
      ll a,b,l,u;
      tie(a,b,l,u)=tmp[i];
      if(i<N-q){
        sum1 -= l*b;
      }else{
        sum1 += u*(X-b);
      }
      if(i<N-(q+1)){
        sum2 -= l*b;
      }else{
        sum2 += u*(X-b);
      }
    }
    for(ll i=0;i<N;i++){
      ll a,b,l,u;
      tie(a,b,l,u)=tmp[i];
      ll sum;
      if(i<N-q){
        sum = sum1;
        sum += l*b;
      }else{
        sum = sum2;
        sum -= u*(X-b);
      }
      if(r>=b){
        sum += u*(r-b);
      }else{
        sum += l*(r-b);
      }
      isok |= sum>=0;
    }
    if(isok){
      high=mid;
    }else{
      low=mid;
    }
  }
  cout<<high<<endl;
  return 0;
}


typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,X;cin>>N>>X;
  vector<tuple<ll,ll,ll,ll> > tmp(N);
  for(ll i=0;i<N;i++){
    ll b,l,u;
    cin>>b>>l>>u;
    tmp[i]=make_tuple(u*X-(u-l)*b,b,l,u);
  }
  sort(tmp.begin(),tmp.end());
  ll low=0,high=X*N+1;
  while(high-low>1){
    ll mid=(high+low)/2;
    ll q = mid/X;
    ll r = mid-q*X;
    ll sum1=0,sum2=0;
    bool isok=false;
    for(ll i=0;i<N;i++){
      ll a,b,l,u;
      tie(a,b,l,u)=tmp[i];
      if(i<N-q){
        sum1 -= l*b;
      }else{
        sum1 += u*(X-b);
      }
      if(i<N-(q+1)){
        sum2 -= l*b;
      }else{
        sum2 += u*(X-b);
      }
    }
    for(ll i=0;i<N;i++){
      ll a,b,l,u;
      tie(a,b,l,u)=tmp[i];
      ll sum;
      if(i<N-q){
        sum = sum1;
        sum += l*b;
      }else{
        sum = sum2;
        sum -= u*(X-b);
      }
      if(r>=b){
        sum += u*(r-b);
      }else{
        sum += l*(r-b);
      }
      isok |= sum>=0;
    }
    if(isok){
      high=mid;
    }else{
      low=mid;
    }
  }
  cout<<high<<endl;
  return 0;
}


Compiler output:
a.cc:6:20: error: expected ';' before 'using'
    6 | using namespace std
      |                    ^
      |                    ;
......
   11 | using namespace std;
      | ~~~~~               
a.cc:85:10: error: redefinition of 'const ll INF'
   85 | const ll INF = LLONG_MAX/10;
      |          ^~~
a.cc:17:10: note: 'const ll INF' previously defined here
   17 | const ll INF = LLONG_MAX/10;
      |          ^~~
a.cc:86:10: error: redefinition of 'const ll MOD'
   86 | const ll MOD = 1e9+7;
      |          ^~~
a.cc:18:10: note: 'const ll MOD' previously defined here
   18 | const ll MOD = 1e9+7;
      |          ^~~
a.cc:88:5: error: redefinition of 'int main()'
   88 | int main(){
      |     ^~~~
a.cc:20:5: note: 'int main()' previously defined here
   20 | int main(){
      |     ^~~~