Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A;
    vector<ll> B;
    ll a = 0;
    ll b = 0;
    for (ll i = 0;i<N;i++) {
        ll aa;
        cin >> aa;
        a += aa;
        if (a > K) break;
        A.push_back(a);
    }
    for (ll i = 0;i<M;i++) {
        ll bb;
        cin >> bb;
        b += bb;
        if (b > K) break;
        B.push_back(b);
    }
    ll ans = 0;
    //reverse(A.begin(),A.end());
    reverse(B.begin(),B.end());
    ll j = 0; //Bをどこまで読むか
    ll i = 0;//A
    while(i < A.size() && j < B.size()) {
        ll atime = A.at(i);
        ll btime = B.at(j);
        if (atime + btime > K) j++;
        else {
            ll s = (i + 1) + (B.size() - j + 1);
            ans = max(s,ans);
    }
    if (B.at(B.end()-1) < K) ans = max(ans,B.size());
    cout << ans << endl;

    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:13: error: no matching function for call to 'std::vector<long long int>::at(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >)'
   46 |     if (B.at(B.end()-1) < K) ans = max(ans,B.size());
      |         ~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]'
 1180 |       at(size_type __n)
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1180:20: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1180 |       at(size_type __n)
      |          ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1199:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::at(size_type) const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&; size_type = long unsigned int]'
 1199 |       at(size_type __n) const
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1199:20: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1199 |       at(size_type __n) const
      |          ~~~~~~~~~~^~~
a.cc:46:39: error: no matching function for call to 'max(ll&, std::vector<long long int>::size_type)'
   46 |     if (B.at(B.end()-1) < K) ans = max(ans,B.size());
      |                                    ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/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:46:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'})
   46 |     if (B.at(B.end()-1) < K) ans = max(ans,B.size());
      |                                    ~~~^~~~~~~~~~~~~~
/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:46:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   46 |     if (B.at(B.end()-1) < K) ans = max(ans,B.size());
      |                                    ~~~^~~~~~~~~~~~~~
a.cc:50:2: error: expected '}' at end of input
   50 | }
      |  ^
a.cc:12:12: note: to match this '{'
   12 | int main() {
      |            ^