Language: C++


#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, K;
int a[5010];
int dp[5010];

bool check(int x) {
  fill(dp, dp+5010, 0);
  dp[0] = 1;
  REP(i, N) {
    if (i == x) continue;
    REPR(j, K+1) {
      if (j-a[i] >= 0) dp[j] |= dp[j-a[i]];
    }
  }
  FOR(i, max(0LL< K-a[x]), K) if (dp[i]) return true;
  return false;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  REP(i, N) cin >> a[i];
  sort(a, a+N);
  int ng = -1, ok = N;
  while (ok-ng > 1) {
    int m = (ng+ok)/2;
    if (check(m)) ok = m;
    else ng = m;
  }
  if (ok < N && check(ok)) cout << ok << endl;
  else cout << N << endl;

  return 0;
}

Compiler output:
a.cc: In function 'bool check(long long int)':
a.cc:38:13: error: no matching function for call to 'max(bool)'
   38 |   FOR(i, max(0LL< K-a[x]), K) if (dp[i]) return true;
      |          ~~~^~~~~~~~~~~~~
a.cc:7:36: note: in definition of macro 'FOR'
    7 | #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
      |                                    ^
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:2:
/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:   candidate expects 2 arguments, 1 provided
/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, 1 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:   template argument deduction/substitution failed:
a.cc:38:13: note:   mismatched types 'std::initializer_list<_Tp>' and 'bool'
   38 |   FOR(i, max(0LL< K-a[x]), K) if (dp[i]) return true;
      |          ~~~^~~~~~~~~~~~~
a.cc:7:36: note: in definition of macro 'FOR'
    7 | #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
      |                                    ^
/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:   candidate expects 2 arguments, 1 provided