Language: C++

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
int main(){
    int n;
    cin>>n;
    ll hh,aa,dd,ss;
    cin>>hh>>aa>>dd>>ss;
    vector<ll> h(n),a(n),d(n),s(n);
    for(int i=0;i<n;i++){
        cin>>h[i]>>a[i]>>d[i]>>s[i];
    }
    ll res=0;
    for(int i=0;i<n;i++){
        if(ss<s[i]){
            res+=max(a[i]-dd,0);
        }
        if(aa<=d[i] || res>=hh){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<ll> ta(n),th(n);
    for(int i=0;i<n;i++){
        ta[i]=max(a[i]-dd,0);
        th[i]=(h[i]/(aa-d[i]))+(h[i]%(aa-d[i])!=0);
        if((th[i]-1)*ta[i]>=hh){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<tuple<int,ll,ll>> ene(n);
    for(int i=0;i<n;i++){
        ene[i]=make_tuple(i,ta[i],th[i]);
    }
    auto comp=[](const tuple<int,ll,ll> &lhs,const tuple<int,ll,ll> rhs){
        return get<2>(lhs)*get<1>(rhs)<get<1>(lhs)*get<2>(rhs);
    };
    sort(ene.begin(),ene.end(),comp);
    vector<int> p(n);
    for(int i=0;i<n;i++){
        p[i]=get<0>(ene[i]);
    }
    ll turn=0;
    for(int i=0;i<n;i++){
        turn+=th[p[i]];
        if(ta[p[i]]!=0 && turn-1>=hh){
            cout<<-1<<endl;
            return 0;
        }
        ll ret=(turn-1)*ta[p[i]];
        if(ret>=hh){
            cout<<-1<<endl;
            return 0;
        }
        res+=ret;
        if(res>=hh){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(res>=hh){
        cout<<-1<<endl;
        return 0;
    }
    cout<<res<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:21: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   17 |             res+=max(a[i]-dd,0);
      |                  ~~~^~~~~~~~~~~
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:17:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |             res+=max(a[i]-dd,0);
      |                  ~~~^~~~~~~~~~~
/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:17:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |             res+=max(a[i]-dd,0);
      |                  ~~~^~~~~~~~~~~
a.cc:26:18: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   26 |         ta[i]=max(a[i]-dd,0);
      |               ~~~^~~~~~~~~~~
/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:26:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   26 |         ta[i]=max(a[i]-dd,0);
      |               ~~~^~~~~~~~~~~
/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:26:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   26 |         ta[i]=max(a[i]-dd,0);
      |               ~~~^~~~~~~~~~~