Language: C++

#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <algorithm>
 
using namespace std;
int main(){
  long long int n,m,k;
  cin >> n >> m >> k;
  long long int a[n];
  long long int b[m];
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  for(int i=0;i<m;++i){
    cin >> b[i];
  }
  long long int A[n+1];
  long long int B[m+1];
  for(int i=0;i<n;++i){
    A[i+1] = A[i] + a[i];
  }
  for(int i=0;i<m;++i){
    B[i+1] = B[i] + b[i];
  }
  int total=0;
  for(int i=0;i<n;++i){
    long long int other = k-A[i];
    if(other < 0){
      continue;
    }
    int l = lower_bound(B[0],B[m-1],other);
    if(l>m || B[l]>other){
      l--;
    }
    total = max(total,i+l);
  }
  cout << total;
 
  return 0;
}

Compiler output:
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: In instantiation of '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = long long int; _Tp = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_val]':
/usr/include/c++/14/bits/stl_algobase.h:1539:32:   required from '_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int; _Tp = long long int]'
 1539 |       return std::__lower_bound(__first, __last, __val,
      |              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
 1540 |                                 __gnu_cxx::__ops::__iter_less_val());
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:24:   required from here
   32 |     int l = lower_bound(B[0],B[m-1],other);
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1495:9: error: no type named 'difference_type' in 'struct std::iterator_traits<long long int>'
 1495 |         _DistanceType;
      |         ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1497:42: error: no matching function for call to 'distance(long long int&, long long int&)'
 1497 |       _DistanceType __len = std::distance(__first, __last);
      |                             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h: In substitution of 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator) [with _InputIterator = long long int]':
/usr/include/c++/14/bits/stl_algobase.h:1497:42:   required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = long long int; _Tp = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_val]'
 1497 |       _DistanceType __len = std::distance(__first, __last);
      |                             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1539:32:   required from '_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int; _Tp = long long int]'
 1539 |       return std::__lower_bound(__first, __last, __val,
      |              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
 1540 |                                 __gnu_cxx::__ops::__iter_less_val());
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:24:   required from here
   32 |     int l = lower_bound(B[0],B[m-1],other);
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: error: no type named 'difference_type' in 'struct std::iterator_traits<long long int>'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~