Language: C++


/**
*    author:  Dooloper
*    created: 27.06.2020 20:58:22
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long n,m,k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  vector<long long> b(m);
  vector<long long> sum1(n);
  vector<long long> sum2(m);
  vector<long long> dp1(n);
  vector<long long> dp2(m);
  int ans = 0;

  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; i++){
    sum1[i] = 0;
    dp1[i] = 0;
  }

  for(int i = 0; i < m; i++){
    sum2[i] = 0;
    dp2[i] = 0;
  }

  int flag1=0,flag2=0;

  for(int i = 0; i < n; i++){
    if(i == 0){
      sum1[i] = a[i];
      continue;
    }
    sum1[i] = sum1[i-1] + a[i];
  }
  for(int i = 0; i < m; i++){
    if(i == 0){
      sum2[i] = b[i];
      continue;
    }
    sum2[i] = sum2[i-1] + b[i];
  }
  int cnt = 0;
  for(int i = 0; i < n; i++){
    cnt = k-sum1[i];
    if(cnt < 0) break;
    if(cnt == 0) ans = max(ans,i+1);
    int minx = 0, miny = m;
    int midxy = 0;
    if(sum1[i] + sum2[m-1] <= k) ans = max(ans,i+1+m);
    while(miny-minx > 1){
      midxy = (minx + miny)/2;
      if(sum2[midxy] > cnt){
        miny = midxy;
      }else{
        minx = midxy;
      }
    }
    if(minx == 0 && sum1[i] + sum2[0] > k) continue;
    ans = max(ans,i+minx+2);
  }
  cnt = 0;
  for(int i = 0; i < m; i++){
    cnt = k-sum2[i];
    if(cnt < 0) break;
    if(cnt == 0) ans = max(ans,i+1);
    int minx = 0, miny = n;
    int midxy = 0;
    if(sum2[i] + sum1[n-1] <= k) ans = max(ans,i+1+n);
    while(miny-minx > 1){
      midxy = (minx + miny)/2;
      if(sum1[midxy] > cnt){
        miny = midxy;
      }else{
        minx = midxy;
      }
    }
    if(minx == 0 && sum2[i] + sum1[0] > k) continue;
    ans = max(ans,i+minx+2);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:43: error: no matching function for call to 'max(int&, long long int)'
   60 |     if(sum1[i] + sum2[m-1] <= k) ans = max(ans,i+1+m);
      |                                        ~~~^~~~~~~~~~~
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:7:
/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:60:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   60 |     if(sum1[i] + sum2[m-1] <= k) ans = max(ans,i+1+m);
      |                                        ~~~^~~~~~~~~~~
/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:60:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   60 |     if(sum1[i] + sum2[m-1] <= k) ans = max(ans,i+1+m);
      |                                        ~~~^~~~~~~~~~~
a.cc:79:43: error: no matching function for call to 'max(int&, long long int)'
   79 |     if(sum2[i] + sum1[n-1] <= k) ans = max(ans,i+1+n);
      |                                        ~~~^~~~~~~~~~~
/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:79:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   79 |     if(sum2[i] + sum1[n-1] <= k) ans = max(ans,i+1+n);
      |                                        ~~~^~~~~~~~~~~
/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:79:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   79 |     if(sum2[i] + sum1[n-1] <= k) ans = max(ans,i+1+n);
      |                                        ~~~^~~~~~~~~~~