Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

bool dpf[5050][5050];
bool dpe[5050][5050];
int main(){
  long long n,k;
  cin>>n>>k;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  
  REP(i,n){
    if(i==0){
      dpf[0][0]=true;
      if(a[i]<=5000){
        dpf[0][a[i]]=true;
      }
    }else{
      REP(x,k+1){
        if(0<=x-a[i] && x-a[i]<=k){
          dpf[i][x] = dpf[i-1][x] | dpf[i-1][x-a[i]];
        }else{
          dpf[i][x] = dpf[i-1][x];
        }
      }
    }
  }
  for(long long i=n-1;i>=0;i--){
    if(i==n-1){
      dpe[i][0]=true;
      if(a[i]<=5000){
        dpe[i][a[i]]=true;
      }
    }else{
      REP(x,k+1){
        if(0<=x-a[i] && x-a[i]<=k){
          dpe[i][x] = dpe[i+1][x] | dpe[i+1][x-a[i]];
        }else{
          dpe[i][x] = dpe[i+1][x];
        }
      }
    }
  }
  long long ans=n;
  REP(i,n){
    
    if(i==0){
      for(int x=max(k-a[i],0);x<k;x++){
        if(dpe[1][x]){
          ans--;
          break;
        }
      }
      continue;
    }
    
    if(i==n-1){
      for(int x=max(k-a[i],0);x<k;x++){
        if(dpf[n-2][x]){
          ans--;
          break;
        }
      }
    }
    
    bool flag=false;
    for(int x=max(k-a[i],0);x<k;x++){
      for(int y=0;y<=x;y++){
        if(dpf[i-1][y] && dpe[i+1][x-y]){
          ans--;
          flag = true;
          break;
        }
      }
      if(flag){
        flag = false;
        break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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