Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

bool check(ll i){
    bitset<5005> dp;
    dp[0]=true;
    rep(j,n){
        if(i==j)continue;
        dp|=dp<<a[j];
    }
    b=0;
    rep(j,k){
        if(!dp[j])continue;
        if(j+a[i]>=k){
            b=1;
            break;
        }
    }
    if(!b)return false;
    else return true;
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n>>k;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll le=0,ri=n-1,mid;
    while(ri-le>1){
        mid=(le+ri)/2;
        if(check(mid))ri=mid;
        else le=mid;
    }
    rrrep(i,min(ri+500,n-1),max(le-500,0LL)){
        bitset<5005> dp;
        dp[0]=true;
        rep(j,n){
            if(i==j)continue;
            dp|=dp<<a[j];
        }
        b=0;
        rep(j,k){
            if(!dp[j])continue;
            if(j+a[i]>=k){
                b=1;
                break;
            }
        }
        if(!b){
            ans=max(ans,i+1);
            break;
        }
    }
    Cout(ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:20: error: no matching function for call to 'max(ll&, int)'
   75 |             ans=max(ans,i+1);
      |                 ~~~^~~~~~~~~
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:75:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   75 |             ans=max(ans,i+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:75:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   75 |             ans=max(ans,i+1);
      |                 ~~~^~~~~~~~~