Language: C++

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
int main(){
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N), B(M);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++) cin >> B[i];

    vector<ll> wa_a(N+1), wa_b(M+1);
    wa_a[0] = 0; wa_b[0] = 0;
    for(int i=1; i<=N; i++) wa_a[i] = wa_a[i-1] + A[i-1];
    for(int i=1; i<=M; i++) wa_b[i] = wa_b[i-1] + B[i-1];
    wa_a.push_back(3e16);
    wa_b.push_back(3e16);
    // cout << "  wa_a:  "; print_vec(wa_a);
    // cout << "  wa_b:  "; print_vec(wa_b);



    //O(NlogN)解法  累積和 + 2分探索
    ll ans = 0;
    for(int num_a=0; num_a<=N; num_a++){
      ll time = K - wa_a[num_a];
      auto iter = upper_bound(wa_b.begin(), wa_b.end(), time);
      auto index = iter - wa_b.begin();
      //cout << "  num_a: " << num_a << " num_b: " << index-1 << endl;
      if(index-1<0) continue;
      ans = max(ans, num_a + index-1);
    }
    cout << ans << endl;

    // O(N+M)解法  累積和 + 尺取り法 (2pointers)
    // ll ans = 0;
    // ll num_a = N;// Aから読む冊数
    // for(int num_b=0; num_b<=M; num_b++){
    //   if(wa_b[num_b] > K) break;
    //   while(wa_a[num_a] + wa_b[num_b] > K){
    //     num_a--;
    //   }

    //   ans = max(ans, num_a + num_b);
    // }

    // cout << ans << endl;


}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:16: error: no matching function for call to 'max(ll&, long int)'
   55 |       ans = max(ans, num_a + index-1);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~
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:55:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   55 |       ans = max(ans, num_a + index-1);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~
/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:55:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |       ans = max(ans, num_a + index-1);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~