Language: C++

#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  long long  n,m,k,cnt=0;
  long long a[300000] = {0};
  long long  b[300000] = {0};

  cin >> n >> m >> k;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if ( i == 0 ) continue;
    if(2147483646-a[i] < a[i-1]) a[i] = 2147483646;
    else if(i!=0) a[i] += a[i-1];
  }

  for(int i = 0; i < m; i++){
    cin >> b[i];
    if ( i == 0) continue;
      if(2147483646-b[i] < b[i-1]) b[i] = 2147483646;
    else if(i!=0) b[i] += b[i-1];
  }
  int nn=n,mm=m;
  for(int i = 0; i < n; i++){
    if (a[i] > k) nn = i;
  }
  for(int i = 0; i < m; i++){
    if (b[i] > k) mm = i;
  }
  if(mm == 0) mm = m;
  if (nn == 0) nn = n;
  int jj = mm-1;
  for(int i = 0; i < n; i++){
    for(int j = jj; j >= 0; j--){
      if(2147483646 - a[i] < b[j]) continue;
      if(a[i] + b[j] <= k) {jj = j;cnt = max(cnt,i+j+2);break;}
    }
  }

  for(int i = nn-1; i >= 0; i --){
    if(a[i] <= k) {cnt = max(cnt,i+1);break;}
  }
  for(int i = mm-1; i >= 0; i --){
    if(b[i] <= k) {cnt = max(cnt,i+1);break;}
  }


  cout << cnt;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:45: error: no matching function for call to 'max(long long int&, int)'
   39 |       if(a[i] + b[j] <= k) {jj = j;cnt = max(cnt,i+j+2);break;}
      |                                          ~~~^~~~~~~~~~~
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:39:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |       if(a[i] + b[j] <= k) {jj = j;cnt = max(cnt,i+j+2);break;}
      |                                          ~~~^~~~~~~~~~~
/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:3:
/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:39:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |       if(a[i] + b[j] <= k) {jj = j;cnt = max(cnt,i+j+2);break;}
      |                                          ~~~^~~~~~~~~~~
a.cc:44:29: error: no matching function for call to 'max(long long int&, int)'
   44 |     if(a[i] <= k) {cnt = max(cnt,i+1);break;}
      |                          ~~~^~~~~~~~~
/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:44:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |     if(a[i] <= k) {cnt = max(cnt,i+1);break;}
      |                          ~~~^~~~~~~~~
/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:44:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |     if(a[i] <= k) {cnt = max(cnt,i+1);break;}
      |                          ~~~^~~~~~~~~
a.cc:47:29: error: no matching function for call to 'max(long long int&, int)'
   47 |     if(b[i] <= k) {cnt = max(cnt,i+1);break;}
      |                          ~~~^~~~~~~~~
/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:47:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   47 |     if(b[i] <= k) {cnt = max(cnt,i+1);break;}
      |                          ~~~^~~~~~~~~
/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:47:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |     if(b[i] <= k) {cnt = max(cnt,i+1);break;}
      |                          ~~~^~~~~~~~~