Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;

const int maxn = 1e5 + 100;

ll all[maxn] = {0}, b[maxn] = {0}, l[maxn] = {0}, u[maxn] = {0}, sum[maxn] = {0};
ll X = 0LL, pr = 0LL;
int id[maxn] = {0};
int n;

bool cmp(int i, int j) { return all[i] > all[j]; }

void init() {
	for (int i = 1; i <= n; ++i) id[i] = i, pr -= l[i] * b[i];
	for (int i = 1; i <= n; ++i) all[i] = b[i] * l[i] + (X - b[i]) * u[i];
	sort(id + 1, id + 1 + n, cmp);
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + all[id[i]];
}

bool check(ll mid) {
	int t = mid / X;
	ll ret = pr;
	ret += sum[t];
	int st = t + 1;
	t = mid % X;
	ll mx = 0LL;
	for (int i = st; i <= n; ++i) mx = max(mx, min(b[id[i]], t) * l[id[i]] + max(0LL, t - b[id[i]]) * u[id[i]]);
	ret += mx;
	return ret >= 0;
}
z
int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> X;
	for (int i = 1; i <= n; ++i) cin >> b[i] >> l[i] >> u[i];
	init();
	ll L = 0LL, R = (ll)n * X;
	while (L < R) {
		int mid = (L + R) >> 1;
		if (check(mid)) R = mid;
		else L = mid + 1;
	}
	cout << R << endl;
	return 0;
}

Compiler output:
a.cc: In function 'bool check(ll)':
a.cc:33:55: error: no matching function for call to 'min(ll&, int&)'
   33 |         for (int i = st; i <= n; ++i) mx = max(mx, min(b[id[i]], t) * l[id[i]] + max(0LL, t - b[id[i]]) * u[id[i]]);
      |                                                    ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:33:55: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |         for (int i = st; i <= n; ++i) mx = max(mx, min(b[id[i]], t) * l[id[i]] + max(0LL, t - b[id[i]]) * u[id[i]]);
      |                                                    ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:33:55: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |         for (int i = st; i <= n; ++i) mx = max(mx, min(b[id[i]], t) * l[id[i]] + max(0LL, t - b[id[i]]) * u[id[i]]);
      |                                                    ~~~^~~~~~~~~~~~~
a.cc: At global scope:
a.cc:37:1: error: 'z' does not name a type
   37 | z
      | ^