Buggy python submission (verdict: Time Limit Exceeded):
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = [0] + LI()


dp1 = [[0]*K for _ in range(N+1)]  # dp1[i][j] = A1~Aiを用いてjを作れるか
dp1[0][0] = 1
for i in range(1,N+1):
    a = A[i]
    for j in range(K):
        if j >= a:
            dp1[i][j] = dp1[i-1][j] | dp1[i-1][j-a]
        else:
            dp1[i][j] = dp1[i-1][j]

dp2 = [[0]*K for _ in range(N+2)]  # dp2[i][j] = Ai~ANを用いてjが作れるか
dp2[N+1][0] = 1
for i in range(N,0,-1):
    a = A[i]
    for j in range(K):
        if j >= a:
            dp2[i][j] = dp2[i+1][j] | dp2[i+1][j-a]
        else:
            dp2[i][j] = dp2[i+1][j]

from itertools import accumulate

ans = 0
for i in range(1,N+1):
    B = list(accumulate(dp2[i+1]))
    for j in range(0,K):
        if j < K-A[i]:
            if dp1[i-1][j] & (B[K-1-j]-B[K-A[i]-j-1] > 0):
                ans += 1
                break
        else:
            if dp1[i-1][j]:
                ans += 1
                break

print(N-ans)


Fixed submission:
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        if i % 2 == 1:
            for j in range(K):
                dp[1][j] = dp[0][j]
                if dp[1][j] == 0 and j >= b:
                    dp[1][j] = dp[0][j-b]
        else:
            for j in range(K):
                dp[0][j] = dp[1][j]
                if dp[0][j] == 0 and j >= b:
                    dp[0][j] = dp[1][j-b]
    if sum(dp[(N-1) % 2 == 1][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)


Fixed submission:
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys

    def MI():
        return map(int, sys.stdin.readline().rstrip().split())

    def LI():
        return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり

    N, K = MI()
    A = LI()
    A.sort()

    def f(n):  # Anが必要か否か
        B = [0] + [A[i] for i in range(N) if i != n]
        dp = [[0] * K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
        dp[0][0] = 1
        for i in range(1, N):
            b = B[i]
            if i % 2 == 1:
                for j in range(K):
                    if j >= b:
                        dp[1][j] = dp[0][j] | dp[0][j - b]
                    else:
                        dp[1][j] = dp[0][j]
            else:
                for j in range(K):
                    if j >= b:
                        dp[0][j] = dp[1][j] | dp[1][j - b]
                    else:
                        dp[0][j] = dp[1][j]
        if sum(dp[(N - 1) % 2][j] for j in range(max(K - A[n], 0), K)) != 0:
            return True
        else:
            return False

    left = -1  # 不必要
    right = N  # 必要
    while left + 1 < right:
        mid = (left + right) // 2
        if f(mid):
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys

    def MI():
        return map(int, sys.stdin.readline().rstrip().split())

    def LI():
        return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり

    N, K = MI()
    A = LI()
    A.sort()

    def f(n):  # Anが必要か否か
        B = [0] + [A[i] for i in range(N) if i != n]
        dp = [[0] * K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
        dp[0][0] = 1
        for i in range(1, N):
            b = B[i]
            if i % 2 == 1:
                for j in range(K):
                    if j >= b:
                        dp[1][j] = dp[0][j] | dp[0][j - b]
                    else:
                        dp[1][j] = dp[0][j]
            else:
                for j in range(K):
                    if j >= b:
                        dp[0][j] = dp[1][j] | dp[1][j - b]
                    else:
                        dp[0][j] = dp[1][j]
        if sum(dp[(N - 1) % 2][j] for j in range(max(K - A[n], 0), K)) != 0:
            return True
        else:
            return False

    left = -1  # 不必要
    right = N  # 必要
    while left + 1 < right:
        mid = (left + right) // 2
        if f(mid):
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        if i % 2 == 1:
            for j in range(K):
                if j >= b:
                    dp[1][j] = dp[0][j] | dp[0][j-b]
                else:
                    dp[1][j] = dp[0][j]
        else:
            for j in range(K):
                if j >= b:
                    dp[0][j] = dp[1][j] | dp[1][j-b]
                else:
                    dp[0][j] = dp[1][j]
    if sum(dp[(N-1) % 2 == 1][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)


Fixed submission:
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Aiが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(N)]  # dp[i][j] = B1~Biを用いてKを作れるか
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i][j] = dp[i-1][j] | dp[i-1][j-b]
            else:
                dp[i][j] = dp[i-1][j]
    if sum(dp[N-1][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)


Fixed submission:
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)