Language: C++

#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gpu_hash_map<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
int n, x;
ll arr[mxN];
array<ll, 2> lr[mxN];
pair<ll, int> takeval[mxN];
ll psum[mxN];
ll bad = 0;
int main() {
    //freopen("greedy.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>x;
    owo(i, 0, n) {
        cin>>arr[i]>>lr[i][0]>>lr[i][1];
        bad-=1LL*lr[i][0]*arr[i];
        takeval[i].first = arr[i]*lr[i][0] + (x-arr[i])*lr[i][1];
        takeval[i].second = i;
    }
    sort(takeval, takeval+n);
    reverse(takeval, takeval+n);
    owo(i, 0, n) {
        psum[i+1] = psum[i] + takeval[i].first;
    }
    ll l = 0;
    ll r = 1LL*n*x;
    while(l<r) {
        ll deficit = bad;
        ll mid = (l+r)/2;
        int tt = mid/x;
        int over = mid-tt*x;
        owo(i, 0, n) {
            ll curr = 0;
            curr+=psum[tt];
            if(i<tt&&tt!=n) {
                curr-=takeval[i].first;
                curr+=takeval[tt].first;
            }
            int id = takeval[i].second;
            curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][1];
            deficit = max(deficit, bad+curr);
        }
        if(deficit>=0) {
            r = mid;
        }else {
            l = mid+1;
        }
    }
    cout<<l<<"\n";
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:26: error: no matching function for call to 'min(int&, ll&)'
   64 |             curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][1];
      |                       ~~~^~~~~~~~~~~~~~
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: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:64:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   64 |             curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][1];
      |                       ~~~^~~~~~~~~~~~~~
/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:
/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:64:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   64 |             curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][1];
      |                       ~~~^~~~~~~~~~~~~~
a.cc:64:60: error: no matching function for call to 'max(int, ll)'
   64 |             curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][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:64:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   64 |             curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][1];
      |                                                         ~~~^~~~~~~~~~~~~~~~
/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
/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:64:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   64 |             curr+=1LL*min(over, arr[i])*lr[id][0] + 1LL*max(0, over-arr[i])*lr[i][1];
      |                                                         ~~~^~~~~~~~~~~~~~~~