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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)


import java.io.*;
import java.util.*;
import java.util.function.IntPredicate;
 
public class Main{
	int N, K;
	int[] A;
	public void solve(){
		N = nextInt();
		K = nextInt();
		A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = nextInt();
		}
		int ans = 0;
		boolean[][] a1 = new boolean[N][K];
		boolean[][] a2 = new boolean[N][K];


		a1[0][0] = true;
		for(int i = 0; i < N - 1; i++){
			for(int j = 0; j < K; j++){
				if(a1[i][j]){
					a1[i + 1][j] = true;
					if(j + A[i] < K){
						a1[i + 1][j + A[i]] = true;
					}
				}
			}
		}
		
		a2[N - 1][0] = true;
		for(int i = N - 1; i > 0; i--){
			for(int j = 0; j < K; j++){
				if(a2[i][j]){
					a2[i - 1][j] = true;
					if(j + A[i] < K){
						a2[i - 1][j + A[i]] = true;
					}
				}
			}
		}
		

		int[][] bit2 = new int[N][1<<13 + 1];
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j < K; j++){
				if(a2[i][j]){
					add(bit2[i], j, 1);
				}
			}
		}
		
		
		for(int i = 0; i < N; i++){
			if(A[i] >= K) continue;
			int kk = K - A[i];
			boolean flg = false;
			for(int j = 0; j < K; j++){
				if(a1[i][j]){
					if(sum(bit2[i], Math.max(0, K - j - 1)) - sum(bit2[i], Math.max(kk - j, -1)) > 0){
						flg = true;
						break;
					}
				}
			}
			if(!flg){
				ans++;
			}
		}
		out.println(ans);
		
	}
	
	int sum(int[] bit, int i) {
		i++;
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int[] bit, int i, int x){
		i++;
		while(i <= (1<<13)){
			bit[i] += x;
			i += i & -i;
		}
	}
	
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}