Language: C++

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
int M = 1e9+7;
 
ll f(int n, int m, int k, vector<vector<ll> > &dp, vector<ll> &A, vector<ll> &B) {
	if(m < 0) {
		ll x = 0;
		for(int i = n; i >= 0; i--) {
			k -= A[i];
			if(k < 0) break;
			x++;
		}
		return x;
	}
	if(n < 0) {
		int x = 0;
		for(int i = m; i >= 0; i--) {
			k -= B[i];
			if(k < 0) break;
			x++;
		}
		return x;
	}
	if(dp[n][m] != -1) return dp[n][m];
	int x = 0;
	if(k >= A[n]) x = 1 + f(n - 1, m, k - A[n], dp, A, B);
	if(k >= B[m]) x = max(x, 1 + f(n, m - 1, k - B[m], dp, A, B));
	dp[n][m] = x;
	return x;
}

int main() {
   
    //Fast IO crap
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	
   	int n, m, k;
   	cin >> n >> m >> k;
   	vector<ll> A(n);
   	vector<ll> B(m);
   	for(int i = 0; i < n; i++) cin >> A[i];
	for(int i = 0; i < m; i++) cin >> B[i];
	for(int i = 0; i < n / 2; i++) {
		swap(A[i], A[n - i - 1]);
	}
	for(int i = 0; i < m / 2; i++) {
		swap(B[i], B[m - i - 1]);
	}
	vector<vector<ll> > dp(n, vector<ll>(m, -1));
	cout << f(n - 1, m - 1, k, dp, A, B);
    return 0;
}


Compiler output:
a.cc: In function 'll f(int, int, int, std::vector<std::vector<long long int> >&, std::vector<long long int>&, std::vector<long long int>&)':
a.cc:30:30: error: no matching function for call to 'max(int&, ll)'
   30 |         if(k >= B[m]) x = max(x, 1 + f(n, m - 1, k - B[m], dp, A, B));
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:30:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   30 |         if(k >= B[m]) x = max(x, 1 + f(n, m - 1, k - B[m], dp, A, B));
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:30:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |         if(k >= B[m]) x = max(x, 1 + f(n, m - 1, k - B[m], dp, A, B));
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~