Language: C++

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

bitset<5010> left[5010], right[5010];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, K; cin >> N >> K;
	vector<int>a(N + 1, -INF); rep(i, 1, N + 1)cin >> a[i];
	sort(all(a));
	int ans(N);
	
	left[0][0] = right[0][0] = 1;
	rep(i, 1, N + 1) {
		left[i] = left[i - 1];
		if (a[i] >= K)continue;
		rrep(j, 0, K - a[i]) {
			if (left[i][j]) {
				left[i][j + a[i]] = 1;
			}
		}
	}
	rep(i, 1, N + 1) {
		right[i] = right[i - 1];
		if (a[N + 1 - i] >= K)continue;
		rrep(j, 0, K - a[i]) {
			if (right[i][j]) {
				right[i][j + a[i]] = 1;
			}
		}
	}

	rep(i, 1, N + 1) {
		if (a[i] >= K) {
			ans--;
			continue;
		}
		// left[i-1]  right[N-i]
		rep(j, 0, K - a[i]) {
			// left[i-1][j] right[N-i][K-a[i]-j]
			bool f(false);
			rep(k, K - a[i] - j, K - j) {
				if (left[i - 1][j] && right[N - i][K - a[i] - j]) {
					f = true;
					break;
				}
			}
			if (f) {
				ans--;
				break;
			}
		}
	}

	//vector<bool>f;
	//rep(i, 0, N) {
	//	f = vector<bool>(K + 100, false);
	//	f[0] = true;
	//	if (a[i] >= K) {
	//		ans++;
	//		continue;
	//	}
	//	rep(j, 0, N) {
	//		if (i == j)continue;
	//		rrep(k, a[j], K + 100) {
	//			f[k] = f[k - a[j]] || f[k];
	//		}
	//	}
	//	bool g(false);
	//	rep(k, K - a[i], K)g = f[k] || g;
	//	ans += g;
	//	dump(ans);
	//	//rep(i, 0, K + 100)cout << i << (i == K + 100 - 1 ? '\n' : ' ');
	//	//rep(i, 0, K + 100)cout << f[i] << (i == K + 100 - 1 ? '\n' : ' ');
	//}

//	cout << ans << endl;

	//sort(all(a));
	//vector<int>s(a);
	//rep(i, 1, N)s[i] += s[i - 1];
	//auto x = lower_bound(all(s), K);
	//if (x == s.end()) {
	//	cout << N << endl;
	//	return 0;
	//}
	//int i(0);
	//while (*x>=K) {
	//	*x -= a[i];
	//	i++;
	//}
	//cout << i-1 << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:9: error: reference to 'left' is ambiguous
   28 |         left[0][0] = right[0][0] = 1;
      |         ^~~~
In file included from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54,
                 from a.cc:1:
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:18:14: note:                 'std::bitset<5010> left [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |              ^~~~
a.cc:28:22: error: reference to 'right' is ambiguous
   28 |         left[0][0] = right[0][0] = 1;
      |                      ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:18:26: note:                 'std::bitset<5010> right [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |                          ^~~~~
a.cc:30:17: error: reference to 'left' is ambiguous
   30 |                 left[i] = left[i - 1];
      |                 ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:18:14: note:                 'std::bitset<5010> left [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |              ^~~~
a.cc:30:27: error: reference to 'left' is ambiguous
   30 |                 left[i] = left[i - 1];
      |                           ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:18:14: note:                 'std::bitset<5010> left [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |              ^~~~
a.cc:33:29: error: reference to 'left' is ambiguous
   33 |                         if (left[i][j]) {
      |                             ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:18:14: note:                 'std::bitset<5010> left [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |              ^~~~
a.cc:34:33: error: reference to 'left' is ambiguous
   34 |                                 left[i][j + a[i]] = 1;
      |                                 ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:18:14: note:                 'std::bitset<5010> left [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |              ^~~~
a.cc:39:17: error: reference to 'right' is ambiguous
   39 |                 right[i] = right[i - 1];
      |                 ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:18:26: note:                 'std::bitset<5010> right [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |                          ^~~~~
a.cc:39:28: error: reference to 'right' is ambiguous
   39 |                 right[i] = right[i - 1];
      |                            ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:18:26: note:                 'std::bitset<5010> right [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |                          ^~~~~
a.cc:42:29: error: reference to 'right' is ambiguous
   42 |                         if (right[i][j]) {
      |                             ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:18:26: note:                 'std::bitset<5010> right [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |                          ^~~~~
a.cc:43:33: error: reference to 'right' is ambiguous
   43 |                                 right[i][j + a[i]] = 1;
      |                                 ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:18:26: note:                 'std::bitset<5010> right [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |                          ^~~~~
a.cc:58:37: error: reference to 'left' is ambiguous
   58 |                                 if (left[i - 1][j] && right[N - i][K - a[i] - j]) {
      |                                     ^~~~
/usr/include/c++/14/bits/ios_base.h:1062:3: note: candidates are: 'std::ios_base& std::left(ios_base&)'
 1062 |   left(ios_base& __base)
      |   ^~~~
a.cc:18:14: note:                 'std::bitset<5010> left [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |              ^~~~
a.cc:58:55: error: reference to 'right' is ambiguous
   58 |                                 if (left[i - 1][j] && right[N - i][K - a[i] - j]) {
      |                                                       ^~~~~
/usr/include/c++/14/bits/ios_base.h:1070:3: note: candidates are: 'std::ios_base& std::right(ios_base&)'
 1070 |   right(ios_base& __base)
      |   ^~~~~
a.cc:18:26: note:                 'std::bitset<5010> right [5010]'
   18 | bitset<5010> left[5010], right[5010];
      |                          ^~~~~