Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll age(ll n, ll d){
	if(n < 0) return -abs(n / d);
	return (n + d - 1) / d;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, x; cin >> n >> x;
	using P = tuple<int,int,int>;
	vector<P> in;
	ll sum = 0, ans = 0;
	rep(i, n){
		int a, b, c; cin >> a >> b >> c;
		in.emplace_back(a, b, c);
		sum -= (ll)a * b;
	}
	sort(all(in),[x]
		(P a, P b){
			return (ll)(x - get<0>(a)) * get<2>(a) + (ll)get<0>(a) * get<1>(a) >
			(ll)(x - get<0>(b)) * get<2>(b) + (ll)get<0>(b) * get<1>(b);
		});
	rep(i, n){
		int b, l, u; tie(b, l, u) = in[i];
		//dbg(b, l, u);
		if(sum + (ll)b * l + (ll)u * (x - b) < 0){
			ans += x;
			sum += (ll)b * l + (ll)u * (x - b);
			continue;
		}
		ll mn = 1e18;
		for(; i < n; i++){
			int b, l, u; tie(b, l, u) = in[i];
			if(sum + (ll)b * l + (ll)u * (x - b) < 0) continue;
			ll r = -(sum + (ll)b * l);
			//dbg(sum, r, b, l, u);
			mn = min(mn, max(0, age(r, l) + b));
			mn = min(mn, age(r, u) + b);
		}
		//dbg(ans, sum, mn);
		ans += mn;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:41: error: no matching function for call to 'max(int, ll)'
   50 |                         mn = min(mn, max(0, age(r, l) + b));
      |                                      ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:50:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   50 |                         mn = min(mn, max(0, age(r, l) + b));
      |                                      ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:50:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   50 |                         mn = min(mn, max(0, age(r, l) + b));
      |                                      ~~~^~~~~~~~~~~~~~~~~~