Language: C++

#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int N,K;
int a[5005];
int dp[5005][5005];
vector<int> A;

bool solve(int i){
    A.erase(A.begin()+i);
    //cout<<a[i]<<endl;
    //for(auto a:A)cout<<a<<" ";
    //cout<<endl;
    int n=A.size();
    for(int j=0;j<=N;++j)for(int k=0;k<=K;++k)dp[j][k]=0;
    if(A[0]<=K)dp[0][A[0]]=1;
    dp[0][0] = 1;
    int res=0;
    for(int j=1;j<n;++j){
        for(int k=0;k<=K;++k){
            if(k-A[j]<0)dp[j][k] = dp[j-1][k];
            else dp[j][k] = (dp[j-1][k]||dp[j-1][k-A[j]]);
        }
    }
    //cout<<i<<endl;
    for(int k=max(0,K-a[i]);k<=K;++k){
        //if(k<0)break;
        if(dp[n-1][k])res=1;
        //cout<<k<<" "<<dp[n-1][k]<<endl;
    }
    A.insert(A.begin()+i,a[i]);
    if(res)return true;
    else return false;
}

signed main(){
    cin>>N>>K;
    for(int i=0;i<N;++i){
        cin>>a[i];
        A.PB(a[i]);
    }
    sort(a,a+N);
    sort(A.begin(),A.end());
    int ans = 0;
    int res;
    int l=0,r=N;
    int mid;
    for(int i=0;i<30;++i){
        mid = (l+r)/2;
        if(solve(mid))r=mid;
        else l=mid;
        //cout<<l<<" "<<r<<" "<<mid<<endl;
    }
    //cout<<l<<" "<<r<<" "<<mid<<endl;
    cout<<l+1<<endl;
}


Compiler output:
a.cc: In function 'bool solve(long long int)':
a.cc:36:18: error: no matching function for call to 'max(int, long long int)'
   36 |     for(int k=max(0,K-a[i]);k<=K;++k){
      |               ~~~^~~~~~~~~~
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: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:36:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   36 |     for(int k=max(0,K-a[i]);k<=K;++k){
      |               ~~~^~~~~~~~~~
/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:36:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |     for(int k=max(0,K-a[i]);k<=K;++k){
      |               ~~~^~~~~~~~~~