Language: C++

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int solve(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector <ll> a(N);
    vector <ll> b(M);
    REP(i, N)cin >> a[i];
    REP(i, M)cin >> b[i];

    vector <ll> a_l_Sum(N+1,0);

    for(int i = 0; i < N; ++i)
    {
        a_l_Sum[i+1] = a[i] + a_l_Sum[i];
    }

    vector <ll> b_l_Sum(M+1,0);

    for(int i = 0; i < M; ++i)
    {
        b_l_Sum[i+1] = b[i] + b_l_Sum[i];
    }


    //なぜかdequeでつなげてたがそんなはずはなかった

    //a[0]～a[n-1] + 
    //b[0]～b[m-1]の最善をみつける

    //a[0]とb[0]は固定
    int res = 0;
    //Aの机の本を何冊読むか
    for(int i = 0; i <= N ; ++i)
    {
        ll l = 0;
        ll r = M+1;
        while (l+1 < r)
        {
            ll mid = (l+r)/2;
            if(a_l_Sum[i] + b_l_Sum[j] <= K)
            {
                l = mid; 
            }
            else r = mid;
        }
        res = max(res, i + l);
    }

    cout << res << endl;

    return 0;
}

int main()
{
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:58:37: error: 'j' was not declared in this scope
   58 |             if(a_l_Sum[i] + b_l_Sum[j] <= K)
      |                                     ^
a.cc:64:18: error: no matching function for call to 'max(int&, ll)'
   64 |         res = max(res, i + l);
      |               ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:64:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   64 |         res = max(res, i + l);
      |               ~~~^~~~~~~~~~~~
/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,
                 from a.cc:6:
/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:64:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   64 |         res = max(res, i + l);
      |               ~~~^~~~~~~~~~~~