Language: C++


#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N, K;
int32_t a[5000];

template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

constexpr int32_t INF = 2'000'000'000;
constexpr int32_t NUMBER = 5000;
int32_t ignore = -1;
int32_t sum[NUMBER + 1];
int8_t dp[NUMBER][NUMBER + 1];
//[i]以降でvalue「に」なるようにとることが可能ならtrue
int8_t func(int i, int value)
{
	if (value <= 0) {
		return value==0;
	}
	//if (i == N) {
	if (sum[i] < value) {
		return false;
	}
	if (dp[i][value] != -2) {
		return dp[i][value];
	}

	auto pata = func(i + 1, value);
	if (i == ignore) {
		return dp[i][value] = std::move(pata);
	}
	return dp[i][value] = (pata | func(i + 1, value - a[i]));
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N >> K;
	for (size_t i = 0; i < N; i++)
	{
		in >> a[i];
		if (a[i] >= K) { --N; --i; }
	}
	std::sort(a, a + N);
	for (int i = N - 1; i >= 0; i--)
	{
		sum[i] = a[i] + sum[i + 1];
	}
	if (sum[0]<K) {
		out << N<<endl;
		return 0;
	}
	using BS_INT = int64_t;
	BS_INT beg = -1, end = N + 1;
	while (beg + 1 != end) {
		BS_INT mid = (beg + end) / 2;

		//ここに書く
		fill_all(dp, -2);
		ignore = mid;
		if (func(0, K - a[mid]) < a[mid] || func(0, K - a[mid]) == INF) {
			end = mid;//必要
		}
		else {
			beg = mid;//不要
		}
	}
	out << beg+1 << endl;

	return 0;
}
#endif

Compiler output:
a.cc: In instantiation of 'void fill_all(ARR&, const T&) [with T = int; ARR = signed char]':
a.cc:34:32:   recursively required from 'void fill_all(ARR&, const T&) [with T = int; ARR = signed char [5001]]'
   34 |         for (auto& i : arr) { fill_all(i, v); }
      |                               ~~~~~~~~^~~~~~
a.cc:34:32:   required from 'void fill_all(ARR&, const T&) [with T = int; ARR = signed char [5000][5001]]'
a.cc:90:11:   required from here
   90 |                 fill_all(dp, -2);
      |                 ~~~~~~~~^~~~~~~~
a.cc:34:9: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   34 |         for (auto& i : arr) { fill_all(i, v); }
      |         ^~~
      |         std::begin
In file included from /usr/include/c++/14/string:53,
                 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:3:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:34:9: error: 'end' was not declared in this scope; did you mean 'std::end'?
   34 |         for (auto& i : arr) { fill_all(i, v); }
      |         ^~~
      |         std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~