Language: C++

#include <bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    vector<ll> sa(n), sb(m);
    cin >> a[0];
    sa[0] = a[0];
    for (int i = 1; i < n; i++)
    {
        cin >> a[i];
        sa[i] = a[i] + sa[i - 1];
    }
    cin >> b[0];
    sb[0] = b[0];
    for (int i = 1; i < m; i++)
    {
        cin >> b[i];
        sb[i] = b[i] + sb[i - 1];
    }
    int ans = 0;
    auto p = lower_bound(sb.begin(), sb.end(), k);
    if (p == sb.end())
    {
        ans = m;
    }
    else
    {
        if (*p > k)
        {
            ans = (p - sb.begin());
        }
        else
        {
            ans = (p - sb.begin()) + 1;
        }
    }
    // cout << "i " << ans << "\n";
    for (int i = 0; i < n; i++)
    {
        ll rem = k - a[i];
        if (rem < 0)
        {
            break;
        }
        auto pos = lower_bound(sb.begin(), sb.end(), rem);
        if (pos == sb.end())
        {
            ans = max(ans, i + 1 + m);
        }
        else
        {
            if (*pos > rem)
            {
                ans = max(ans, i + 0 + (pos - sb.begin()));
            }
            else
            {
                ans = max(ans, i + 1 + (pos - sb.begin()));
            }
        }
        // cout << ans << ",";
    }
    cout << ans;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:26: error: no matching function for call to 'max(int&, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   70 |                 ans = max(ans, i + 0 + (pos - sb.begin()));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:70:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   70 |                 ans = max(ans, i + 0 + (pos - sb.begin()));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:70:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   70 |                 ans = max(ans, i + 0 + (pos - sb.begin()));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:74:26: error: no matching function for call to 'max(int&, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   74 |                 ans = max(ans, i + 1 + (pos - sb.begin()));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:74:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   74 |                 ans = max(ans, i + 1 + (pos - sb.begin()));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:74:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   74 |                 ans = max(ans, i + 1 + (pos - sb.begin()));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~