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# (.NET Core 3.1.201) (judge verdict: Memory Limit Exceeded)

using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K) = Slice2<long>();
            //Kより大きいものは単体で良い集合になるので必要なカード
            //ほかのと組み合わせてもそれ以外は不要にできるので考慮しないで良い
            var ai = Sarray().Where(a => a <= K).ToArray();
            N = ai.Length;
            //aiなしでK-ai～K-1を作ることができればaiは必要なカード
            //毎回ai無しで作れる数を求めてたらTLEなので挟み撃ちでなんとかする
            //left:ai未満で作れる数
            //right:aiより大きなもので作れる数
            var left = new long[N + 1, K + 1];//0:0,1:a1,2:(a1,a2),･･･,N:(a1,a2,･･･,aN)
            var right = new long[N + 1, K + 1];//0:0,1:aN,2:(aN-1,aN),･･･N:(a1,a2,･･･aN)
            left[0, 0] = 1;
            right[0, 0] = 1;
            for (var i = 1; i <= N; ++i)
            {
                for (var j = 0; j <= K; ++j)
                {
                    if (left[i - 1, j] == 1)
                    {
                        left[i, j] = 1;
                        if (j + ai[i - 1] <= K)
                            left[i, j + ai[i - 1]] = 1;
                    }
                    if (right[i - 1, j] == 1)
                    {
                        right[i, j] = 1;
                        if (j + ai[N - i] <= K)
                            right[i, j + ai[N - i]] = 1;
                    }
                }
            }
            //aiを使わないとき、～ai)から[ai+1～が満たせばよい数値を作る
            var imos = new long[N + 1, K + 2];
            for (var i = 0; i < N; ++i)
            {
                for (var j = 0; j <= K; ++j)
                {
                    if (left[i, j] == 1)
                    {
                        imos[i, Max(0,K - ai[i] - j)] += 1;
                        imos[i, Max(0, K - j)] -= 1;
                    }
                }
                for (var j = 1; j <= K; ++j)
                    imos[i, j] += imos[i, j - 1];
            }
            var cnt = 0L;
            for (var i = 0; i < N; ++i)
            {
                var used = false;
                for (var j = 0; j <= K; ++j)
                {
                    //a_iを使わないとき、ai+1～aNでimosが1の値を作ることができれば必要なカード
                    //imos[i,]:a_iを使わない場合
                    //right[N-1-i,]:aN～ai+1を使う
                    if (0 < imos[i, j] && 0 < right[N - 1 - i, j])
                        used = true;
                }
                if (!used)
                    ++cnt;
            }
            WriteLine(cnt);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}