Language: C++


// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 *   ﷽
 * In the name of Allah, the Most Gracious, the Most Merciful
 */

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

template <class T> int binser(T const &ref, long long key)
{
    int low = 0;
    int high = ref.size();

    while (low < high)
    {
        int mid = low + (high - low) / 2;
        if (ref[mid] == key)
            return mid;
        else if (ref[mid] > key)
            high = mid - 1;
        else
            low = mid + 1;
    }
    return ref[low] > key ? low - 1 : low;
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (auto &e : a)
        cin >> e;
    for (auto &e : b)
        cin >> e;

    vector<long long int> A, B;
    A.push_back(0);
    A.push_back(a[0]);
    B.push_back(0);
    B.push_back(b[0]);

    for (int t = 1; t < n; t++)
        A.push_back(A[A.size() - 1] + a[t]);

    for (int t = 1; t < m; t++)
        B.push_back(B[B.size() - 1] + b[t]);

    int ans = 0;
    for (int a = 0; a < n + 1 && k >= A[a]; a++)
        ans = max(ans, a + upper_bound(B.begin(), B.end(), k - A[a]) - B.begin() - 1);

    cout << ans;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:66:18: error: no matching function for call to 'max(int&, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   66 |         ans = max(ans, a + upper_bound(B.begin(), B.end(), k - A[a]) - B.begin() - 1);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:14:
/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:66:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   66 |         ans = max(ans, a + upper_bound(B.begin(), B.end(), k - A[a]) - B.begin() - 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:66:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   66 |         ans = max(ans, a + upper_bound(B.begin(), B.end(), k - A[a]) - B.begin() - 1);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~