Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a,b;
  int n,m,k;
  cin>>n>>m>>k;
  int sum =0;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    a.push(x);
  }
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    b.push(x);
  }
  bool ans = false;
  while(!a.empty() && !b.empty()){
    if(sum + min(a.top(),b.top) > k){
      ans = true;
      break;
    }
      if(a.top()<b.top(){
        sum += a.top();
        a.pop();
      }else{
        sum += b.top();
        b.pop();
      }
   }
   if(!ans){
      while(!a.empty()){
        if(sum + a.top()<=k){
          sum += a.top();
          a.pop();
        }else{
          break;
        }
      }
        while(!b.empty()){
          if(sum + b.top()<=k){
            sum += b.top();
            b.pop();
          }else{
            break;
          }
        }
     }
         cout<<sum;
         return 0;
         }
         

Compiler output:
a.cc: In function 'int main()':
a.cc:20:17: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, <unresolved overloaded function type>)'
   20 |     if(sum + min(a.top(),b.top) > k){
      |              ~~~^~~~~~~~~~~~~~~
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: 'constexpr const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:36: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to 'const int&'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |                         ~~~~~~~~~~~^~~
/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:20:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   20 |     if(sum + min(a.top(),b.top) > k){
      |              ~~~^~~~~~~~~~~~~~~
a.cc:24:25: error: expected ')' before '{' token
   24 |       if(a.top()<b.top(){
      |         ~               ^
      |                         )
a.cc:31:4: error: expected primary-expression before '}' token
   31 |    }
      |    ^