Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
 
int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    cin >> a[0];
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        a[i] += a[i-1];
    }
    cin >> b[0];
    for (int i = 1; i < m; i++) {
        cin >> b[i];
        b[i] += b[i-1];
    }
    
    ll na = -1;
    ll ans = 0;
    for (int i = (int)b.size()-1; i>=0; i--) {
        if ((b[i]>k)) {
            continue;
        }
        while (na<n-1) {
            if ((a[na+1]+b[i]<=k)) {
                na++;
            }else{
                break;
            }
        }
        if (na == -1) {
            if ((b[i]<=k)) {
                ans = max(ans, na+i+2);
            }
        }else {
            if ((a[na]+b[i]<=k)) {
                ans = max(ans, na+i+2);
            }
        }
        
        
    }
    if(ans == 0){
        REP(i, n){
            if (a[i]<=k) {
                chmax(ans, i+1);
            }
        }
    }
    COUT(ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:92:22: error: no matching function for call to 'chmax(ll&, int)'
   92 |                 chmax(ans, i+1);
      |                 ~~~~~^~~~~~~~~~
a.cc:44:27: note: candidate: 'template<class T> bool chmax(T&, const T&)'
   44 | template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
      |                           ^~~~~
a.cc:44:27: note:   template argument deduction/substitution failed:
a.cc:92:22: note:   deduced conflicting types for parameter 'const T' ('long long int' and 'int')
   92 |                 chmax(ans, i+1);
      |                 ~~~~~^~~~~~~~~~