Problem:
Score : 600 points

Problem Statement

AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i.
Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.

Then, for each card i, he judges whether it is unnecessary or not, as follows:

If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.

Otherwise, card i is NOT unnecessary.

Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.

Constraints

All input values are integers.

1≤N≤5000

1≤K≤5000

1≤a_i≤10^9 (1≤i≤N)

Partial Score

300 points will be awarded for passing the test set satisfying N,K≤400.

Input

The input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the number of the unnecessary cards.

Sample Input 1

3 6
1 4 3

Sample Output 1

1

There are two good sets: {2,3} and {1,2,3}.

Card 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.

For card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.

Neither is card 3 for a similar reason, hence the answer is 1.

Sample Input 2

5 400
3 1 4 1 5

Sample Output 2

5

In this case, there is no good set. Therefore, all the cards are unnecessary.

Sample Input 3

6 20
10 4 3 10 25 2

Sample Output 3

3

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>


#define NITEM(arr) (sizeof(arr)/sizeof(arr[0]))


typedef int (*cmp_t)(const void *, const void *);


#define N_MAX 5000
#define K_MAX 5000


int cmpint(const int *a, const int *b)
{
	return *b-*a;
}


int max(int a, int b)
{
	if(a>b) return a;
	return b;
}

int min(int a, int b)
{
	if(a<b) return a;
	return b;
}

void max_update(int *max, int x)
{
	if(*max<x) *max=x;
}

int main(void)
{
	int N, K, i, j, k, need, prev_is_need;
	static int a[N_MAX];
	static char forward[N_MAX+1][K_MAX+1];
	static char backward[N_MAX+1][K_MAX+1];
	static char mix[K_MAX+1];
	static int forward_max[N_MAX+1], backward_max[N_MAX+1];

	while(scanf("%d%d", &N, &K)==2)
	{
		for(i=0;i<N;i++)
		{
			scanf("%d", &a[i]);
		}

		qsort(a, N, sizeof(a[0]), (cmp_t)cmpint);

		memset(forward_max, 0, sizeof(forward_max));
		memset(backward_max, 0, sizeof(backward_max));
		memset(forward, 0, sizeof(forward));
		memset(backward, 0, sizeof(backward));
		forward[0][0]=backward[N][0]=1;
		for(i=0;i<N;i++)
		{
			memcpy(forward[i+1], forward[i], sizeof(mix));
			forward_max[i+1]=forward_max[i];
			for(j=0;j+a[i]<=K;j++)
			{
				if(forward[i][j]==0) continue;

				forward[i+1][j+a[i]]|=forward[i][j];
				max_update(&forward_max[i+1], j+a[i]);
			}
		}
		for(i=N-1;i>=0;i--)
		{
			memcpy(backward[i], backward[i+1], sizeof(mix));
			backward_max[i]=backward_max[i+1];
			for(j=0;j+a[i]<=K;j++)
			{
				if(backward[i+1][j]==0) continue;

				backward[i][j+a[i]]|=backward[i+1][j];
				max_update(&backward_max[i], j+a[i]);
			}
		}
/*
		printf("forward\n");
		for(i=0;i<=N;i++)
		{
		for(j=0;j<=K;j++) printf(" %d", forward[i][j]);
		printf("\n");
		}

		printf("backward\n");
		for(i=0;i<=N;i++)
		{
		for(j=0;j<=K;j++) printf(" %d", backward[i][j]);
		printf("\n");
		}
*/
		need=0;
		prev_is_need=0;
		for(i=0;i<N;i++)
		{
			if(i && a[i]==a[i-1] && prev_is_need)
			{
				need++;
				continue;
			}

			if(forward_max[i]+backward_max[i+1]+a[i]<K) continue;

			prev_is_need=0;
			memset(mix, 0, sizeof(mix));
			for(j=K-1;j>=0;j--)
			{
				if(forward[i][j]==0) continue;
				for(k=K-j-1;k>=0;k--)
				{
					if(backward[i+1][k])
					{
						mix[k+j]|=backward[i+1][k];
						if(k+j>=K-a[i])
						{
							prev_is_need=1;
							need++;
							break;
						}
					}
				}
				if(prev_is_need) break;
			}
/*
			printf("%3d mix ", i);
			for(k=0;k<=K;k++) printf(" %d", mix[k]);
			printf("\n");
*/
/*
			prev_is_need=0;
			for(k=max(K-a[i], 0);k<K;k++)
			{
				if(mix[k])
				{
//					printf("need\n");
					prev_is_need=1;
					need++;
					break;
				}
			}
*/
		}
		printf("%d\n", N-need);
	}

	return 0;
}