Language: C++

//
//  main.cpp
//  atcoder-candies
//
//  Created by r on 6/1/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

long long N,K;
long long pref[100010];
long long currpref[100010];
long long dp[110][100010];
long long a[100010];

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for (long long i = 1; i<=N; i++) {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (long long i = 0; i<=K; i++) {
        pref[i+1]+=pref[i];
        pref[i+1]+=dp[0][i];
    }
    for (long long i = 1; i<=N; i++) {
        for (long long j = 0; j<=K; j++) {
            dp[i][j] = pref[j+1]-pref[max(0, j-a[i])];
            currpref[j+1]+=currpref[j];
            currpref[j+1]+=dp[i][j];
        }
        memcpy(pref, currpref, sizeof(pref));
        memset(currpref, 0, sizeof(currpref));
    }
    cout << dp[N][K] << endl;
    return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:56:42: error: no matching function for call to 'max(int, long long int)'
   56 |             dp[i][j] = pref[j+1]-pref[max(0, j-a[i])];
      |                                       ~~~^~~~~~~~~~~
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:9:
/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:56:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   56 |             dp[i][j] = pref[j+1]-pref[max(0, j-a[i])];
      |                                       ~~~^~~~~~~~~~~
/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:10:
/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:56:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   56 |             dp[i][j] = pref[j+1]-pref[max(0, j-a[i])];
      |                                       ~~~^~~~~~~~~~~