Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [e for e in a if e < k]
n = len(a)

dp = np.zeros((n + 1, k), bool)
dp[0][0] = True
for i, e in enumerate(a, 1):
    dp[i] = dp[i-1]
    dp[i, e:] |= dp[i-1, :-e]

dp2 = np.zeros((n + 1, k), bool)
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    dp2[i] = dp2[i-1]
    dp2[i, e:] |= dp2[i-1, :-e]

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while j > 0 and e2 + li2[j] >= k:
            j -= 1

        if e2 + li2[j] < k:
            mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [e for e in a if e < k]
n = len(a)

dp = [[False] * k for _ in range(n + 1)]
dp[0][0] = True
for i, e in enumerate(a, 1):
    for j in range(k):
        dp[i][j] = dp[i-1][j]

    for j in range(k - e):
        if dp[i-1][j]:
            dp[i][j+e] = True

dp2 = [[False] * k for _ in range(n + 1)]
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    for j in range(k):
        dp2[i][j] = dp2[i-1][j]

    for j in range(k - e):
        if dp2[i-1][j]:
            dp2[i][j+e] = True

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while e2 + li2[j] >= k:
            j -= 1

        mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [[False] * k for _ in range(n + 1)]
dp[0][0] = True
for i, e in enumerate(a, 1):
    for j in range(k):
        dp[i][j] = dp[i-1][j]

    for j in range(k - e):
        if dp[i-1][j]:
            dp[i][j+e] = True

dp2 = [[False] * k for _ in range(n + 1)]
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    for j in range(k):
        dp2[i][j] = dp2[i-1][j]

    for j in range(k - e):
        if dp2[i-1][j]:
            dp2[i][j+e] = True

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while e2 + li2[j] >= k:
            j -= 1

        mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Runtime Error):
import numpy as np
from numba import njit

n, k = map(int, input().split())
a = tuple(map(int, input().split()))

dp = np.zeros((n + 1, k), bool)
dp[0][0] = True
for i, e in enumerate(a, 1):
    dp[i] = dp[i-1]
    dp[i, e:] |= dp[i-1, :-e]

dp2 = np.zeros((n + 1, k), bool)
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    dp2[i] = dp2[i-1]
    dp2[i, e:] |= dp2[i-1, :-e]


@njit
def f(a, dp, dp2):
    ret = 0
    for i, e in enumerate(a, 1):
        li = [j for j in range(k) if dp[i-1][j]]
        li2 = [j for j in range(k) if dp2[n-i][j]]

        j = len(li2) - 1
        mx = 0
        for e2 in li:
            while j > 0 and e2 + li2[j] >= k:
                j -= 1

            if e2 + li2[j] < k:
                mx = max(mx, e2 + li2[j])

        if mx + e < k:
            ret += 1

    return ret


ans = f(a, dp, dp2)
print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = np.zeros((n + 1, k), bool)
dp[0][0] = True
for i, e in enumerate(a, 1):
    dp[i] = dp[i-1]
    dp[i, e:] |= dp[i-1, :-e]

dp2 = np.zeros((n + 1, k), bool)
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    dp2[i] = dp2[i-1]
    dp2[i, e:] |= dp2[i-1, :-e]

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while j > 0 and e2 + li2[j] >= k:
            j -= 1

        if e2 + li2[j] < k:
            mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Runtime Error):
from numba import njit


@njit
def solve(n, k, a):
    dp = [[0] * k for _ in range(n + 1)]
    dp[0][0] = 1
    for i, e in enumerate(a, 1):
        for j in range(k):
            dp[i][j] = dp[i-1][j]

        for j in range(k - e):
            if dp[i-1][j]:
                dp[i][j+e] = 1

    dp2 = [[0] * k for _ in range(n + 1)]
    dp2[0][0] = 1
    for i, e in enumerate(a[::-1], 1):
        for j in range(k):
            dp2[i][j] = dp2[i-1][j]

        for j in range(k - e):
            if dp2[i-1][j]:
                dp2[i][j+e] = 1

    ans = 0
    for i, e in enumerate(a, 1):
        li = [j for j in range(k) if dp[i-1][j]]
        li2 = [j for j in range(k) if dp2[n-i][j]]

        j = len(li2) - 1
        mx = 0
        for e2 in li:
            while j > 0 and e2 + li2[j] >= k:
                j -= 1

            if e2 + li2[j] < k:
                mx = max(mx, e2 + li2[j])

        if mx + e < k:
            ans += 1

    print(ans)


if __name__ == "__main__":
    n, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    solve(n, k, a)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [[0] * k for _ in range(n + 1)]
dp[0][0] = 1
for i, e in enumerate(a, 1):
    for j in range(k):
        dp[i][j] = dp[i-1][j]

    for j in range(k - e):
        if dp[i-1][j]:
            dp[i][j+e] = 1

dp2 = [[0] * k for _ in range(n + 1)]
dp2[0][0] = 1
for i, e in enumerate(a[::-1], 1):
    for j in range(k):
        dp2[i][j] = dp2[i-1][j]

    for j in range(k - e):
        if dp2[i-1][j]:
            dp2[i][j+e] = 1

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while j > 0 and e2 + li2[j] >= k:
            j -= 1

        if e2 + li2[j] < k:
            mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp_l = [[0] * (k + 1) for _ in range(n + 1)]
dp_l[0][0] = 1

for i, e in enumerate(a):
    for j in range(k + 1):
        dp_l[i+1][j] += dp_l[i][j]
        nxt = min(k, j + e)
        dp_l[i+1][nxt] += dp_l[i][j]

dp_r = [[0] * (k + 1) for _ in range(n + 1)]
dp_r[0][0] = 1

for i, e in enumerate(a[::-1]):
    for j in range(k + 1):
        dp_r[i+1][j] += dp_r[i][j]
        nxt = min(k, j + e)
        dp_r[i+1][nxt] += dp_r[i][j]

for i in range(n + 1):
    for j in range(k, 0, -1):
        dp_r[i][j-1] += dp_r[i][j]

base = dp_l[n][k]
ans = 0
for i in range(1, n + 1):
    cnt = 0
    for j in range(k + 1):
        cnt += dp_l[i-1][j] * dp_r[n-i][k-j]
    if 2 * cnt == base:
        ans += 1

print(ans)


Fixed submission:
import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)