Language: C++

#include <bits/stdc++.h>
using namespace std;
int N,M,K;
std::vector<int> A;
std::vector<int> B;
int mina = 9999999;
int d = 0;
int search(int t,int i,int j){
     
     if(t>=K){
          
          if(d<mina){
              
               mina = d;
          }
          return 1;
     }
     if(i<N){
          search(t+A[i],i+1,j,d);
          d+=1;
     }
     
     if(j<M){
          d-=1;
          search(t+B[j],i,j+1,d);
          d+=1;
     }
}
int main() { 
     
     cin >> N >> M >> K;
     for(int i=0;i<N;i+=1){
          int x;
          cin >> x;
          A.push_back(x);
     }
     for(int i=0;i<M;i+=1){
          int x;
          cin >> x;
          B.push_back(x);
     }
     search(0,0,0);
     cout << mina;
}


Compiler output:
a.cc: In function 'int search(int, int, int)':
a.cc:19:17: warning: ignoring return value of '_FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int; _FIter2 = int]', declared with attribute 'nodiscard' [-Wunused-result]
   19 |           search(t+A[i],i+1,j,d);
      |           ~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: declared here
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
a.cc:25:17: warning: ignoring return value of '_FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int; _FIter2 = int]', declared with attribute 'nodiscard' [-Wunused-result]
   25 |           search(t+B[j],i,j+1,d);
      |           ~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: declared here
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_iter<int>]':
/usr/include/c++/14/bits/stl_algobase.h:2203:23:   required from '_ForwardIterator1 std::__search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate) [with _ForwardIterator1 = int; _ForwardIterator2 = int; _BinaryPredicate = __gnu_cxx::__ops::_Iter_equal_to_iter]'
 2203 |         return std::__find_if(__first1, __last1,
      |                ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
 2204 |                 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4102:27:   required from '_FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int; _FIter2 = int]'
 4102 |       return std::__search(__first1, __last1, __first2, __last2,
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 4103 |                            __gnu_cxx::__ops::__iter_equal_to_iter());
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:17:   required from here
   19 |           search(t+A[i],i+1,j,d);
      |           ~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2153:48: error: no matching function for call to '__iterator_category(int&)'
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:65:
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note: candidate: 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&)'
  239 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator_base_types.h: In substitution of 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&) [with _Iter = int]':
/usr/include/c++/14/bits/stl_algobase.h:2153:34:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_iter<int>]'
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2203:23:   required from '_ForwardIterator1 std::__search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate) [with _ForwardIterator1 = int; _ForwardIterator2 = int; _BinaryPredicate = __gnu_cxx::__ops::_Iter_equal_to_iter]'
 2203 |         return std::__find_if(__first1, __last1,
      |                ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
 2204 |                 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4102:27:   required from '_FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int; _FIter2 = int]'
 4102 |       return std::__search(__first1, __last1, __first2, __last2,
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 4103 |                            __gnu_cxx::__ops::__iter_equal_to_iter());
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:17:   required from here
   19 |           search(t+A[i],i+1,j,d);
      |           ~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'
  239 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_equal_to_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = int; _Iterator2 = int]':
/usr/include/c++/14/bits/stl_algobase.h:2223:22:   required from '_ForwardIterator1 std::__search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate) [with _ForwardIterator1 = int; _ForwardIterator2 = int; _BinaryPredicate = __gnu_cxx::__ops::_Iter_equal_to_iter]'
 2223 |           while (__predicate(__current, __p))
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4102:27:   required from '_FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int; _FIter2 = int]'
 4102 |       return std::__search(__first1, __last1, __first2, __last2,
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 4103 |                            __gnu_cxx::__ops::__iter_equal_to_iter());
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:17:   required from here
   19 |           search(t+A[i],i+1,j,d);
      |           ~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:117:16: error: invalid type argument of unary '*' (have 'int')
  117 |       { return *__it1 == *__it2; }
      |                ^~~~~~
/usr/include/c++/14/bits/predefined_ops.h:117:26: error: invalid type argument of unary '*' (have 'int')
  117 |       { return *__it1 == *__it2; }
      |                          ^~~~~~
a.cc:28:1: warning: control reaches end of non-void function [-Wreturn-type]
   28 | }
      | ^