Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left


N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

dp1 = [[False] * (K + 1) for _ in range(N + 1)]

for i in range(N + 1):
    dp1[i][0] = True
for i in range(N):
    a = A[i]
    d = K if a >= K else a - 1
    for j in range(K, d, -1):
        dp1[i + 1][j] = dp1[i][j] | dp1[i][j - a]

dp2 = [[False] * (K + 1) for _ in range(N + 1)]
for i in range(N + 1):
    dp2[i][0] = True
for i in range(N):
    a = A[N - 1 - i]
    d = K if a >= K else a - 1
    for j in range(K, d, -1):
        dp2[i + 1][j] = dp2[i][j] | dp2[i][j - a]


def solve(i):
    d1 = []
    d2 = []
    n = A[i]
    for j, k in enumerate(dp1[i]):
        if k:
            d1.append(j)
    for j, k in enumerate(dp2[N - 1 - i]):
        if k:
            d2.append(j)
    for a in d1:
        l = bisect_left(d2, K - n - a)
        r = bisect_left(d2, K - a)
        if r - l >= 1:
            return True
    return False


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid


print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left


N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

dp1 = [[0] * (K + 1) for _ in range(N + 1)]

for i in range(N + 1):
    dp1[i][0] = 1
for i in range(N):
    a = A[i]
    d = K if a >= K else a - 1
    for j in range(K, d, -1):
        dp1[i + 1][j] = dp1[i][j] | dp1[i][j - a]

dp2 = [[0] * (K + 1) for _ in range(N + 1)]
for i in range(N + 1):
    dp2[i][0] = 1
for i in range(N):
    a = A[N - 1 - i]
    d = K if a >= K else a - 1
    for j in range(K, d, -1):
        dp2[i + 1][j] = dp2[i][j] | dp2[i][j - a]


def solve(i):
    d1 = []
    d2 = []
    n = A[i]
    for j, k in enumerate(dp1[i]):
        if k:
            d1.append(j)
    for j, k in enumerate(dp2[N - 1 - i]):
        if k:
            d2.append(j)
    for a in d1:
        l = bisect_left(d2, K - n - a)
        r = bisect_left(d2, K - a)
        if r - l >= 1:
            return True
    return False


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid


print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right


N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

dp1 = [[0] * (K + 1) for _ in range(N + 1)]
dp1[0][0] = 1
for i in range(N):
    a = A[i]
    for j in range(K + 1):
        here = dp1[i][j]
        dp1[i + 1][min(K, j + a)] |= here
        dp1[i + 1][j] |= here

dp2 = [[0] * (K + 1) for _ in range(N + 1)]
dp2[0][0] = 1
for i in range(N):
    a = A[N - 1 - i]
    for j in range(K + 1):
        here = dp2[i][j]
        dp2[i + 1][min(K, j + a)] |= here
        dp2[i + 1][j] |= here

cnt = 0
for i in range(N):
    d1 = []
    d2 = []
    n = A[i]
    for j, k in enumerate(dp1[i]):
        if k:
            d1.append(j)
    for j, k in enumerate(dp2[N - 1 - i]):
        if k:
            d2.append(j)
    for a in d1:
        l = bisect_left(d2, K - n - a)
        r = bisect_left(d2, K - a)
        if r - l >= 1:
            cnt += 1
            break
    
print(N - cnt)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    n = mid
    dp = set()
    dp.add(0)
    ans = set(x for x in range(max(0, K - A[n] + 1), K))
    for i in range(N):
        a = A[i]
        if i == n or a >= K:
            continue
        for j in range(K - a - 1, -1, -1):
            if j in dp:
                if j + a in ans:
                    rst = True
                    break
                else:
                    dp.add(j + a)
        else:
            rst = False
    if rst:
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    n = mid
    dp = set()
    dp.add(0)
    for i in range(N):
        a = A[i]
        if i == n or a >= K:
            continue
        for j in range(K - a - 1, -1, -1):
            if j in dp:
                dp.add(j + a)
    rst = any(k in dp for k in range(max(0, K - A[n]), K))
    if rst:
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    n = mid
    dp = [0] * (K + 1)
    dp[0] = 1
    for i in range(N):
        a = A[i]
        if i == n or a >= K:
            continue
        for j in range(K, -1, -1):
            dp[min(K, j + a)] |= dp[j]
    rst = any(dp[k] for k in range(max(0, K - A[n]), K))
    if rst:
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    n = mid
    dp = [0] * (K + 1)
    dp[0] = 1
    for i in range(N):
        a = 0 if i == n else A[i]
        for j in range(K, -1, -1):
            dp[min(K, j + a)] |= dp[j]
    rst = any(dp[k] for k in range(max(0, K - A[n]), K))
    if rst:
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(n):
    global N, K
    dp = [[0] * (K + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        a = 0 if i == n else A[i]
        for j in range(max(0, K - a + 1)):
            here = dp[i][j]
            dp[i + 1][j + a] |= here
            dp[i + 1][j] |= here
    rst = any(dp[N][k] for k in range(max(0, K - A[n]), K))
    return rst


N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    n = mid
    dp = [[0] * (K + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        a = 0 if i == n else A[i]
        for j in range(K + 1):
            here = dp[i][j]
            dp[i + 1][min(K, j + a)] |= here
            dp[i + 1][j] |= here
    rst = any(dp[N][k] for k in range(max(0, K - A[n]), K))
    if rst:
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()

Buggy python submission (verdict: Runtime Error):
def solve(n):
    global N, K
    dp = [[0] * (K + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        a = 0 if i == n else A[i]
        for j in range(K + 1):
            dp[i + 1][min(K, j + a)] |= dp[i][j]
            dp[i + 1][j] |= dp[i][j]
    rst = any(dp[N][k] for k in range(K - A[n], K))
    return rst


N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()