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

A.sort()
# print(A)

le = -1
ri = len(A)
mid = (le + ri) // 2
while ri - le > 1:
    # print(le,ri,mid)
    DP = [0 for i in range(k)]
    DP[0] = 1
    for i in range(n):
        #print(DP)
        if i != mid:
            for p in range(k-1, A[i]-1, -1):
                DP[p] = int(DP[p-A[i]] or DP[p])
        # print(j)
    need = 0
    #print(DP)
    for p in range(max(0, k-A[mid]), k):
        if DP[p] == 1:
            need = 1
            break
    
    if need == 1:
        ri = mid
    else:
        le = mid
    mid = (le + ri) // 2

print(le + 1)

Fixed submission:
n, k = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
# print(A)
A_set = list(set(A))

A_set = [int(i) for i in A_set]
A_set.sort()

#print(A_set)

le = -1
ri = len(A_set)
mid = (le + ri) // 2

while ri - le > 1:
    need = 0
    # print(le,ri,mid)

    DP = [0 for i in range(k)]
    DP[0] = 1
    jogai = 0
    for i in range(n):
        #print(DP)
        if jogai == 0 and A[i] == A_set[mid]:
            jogai = 1
        else:
            for p in range(k-1, A[i]-1, -1):
                DP[p] = int(DP[p-A[i]] or DP[p])
            # print(j)
    
            #print(DP)
        for p in range(max(0, k-A_set[mid]), k):
            if DP[p] == 1:
                need = 1
                break
        if need == 1:
            break
    
    if need == 1:
        ri = mid
    else:
        le = mid
    mid = (le + ri) // 2


ans = 0

if le != -1:
    jougen = A_set[le]
    for i in range(n):
        if A[i] <= jougen:
            ans += 1

print(ans)

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

A.sort()
# print(A)

le = -1
ri = len(A)
mid = (le + ri) // 2
while ri - le > 1:
    # print(le,ri,mid)
    DP = [0] * k
    DP[0] = 1
    for i in range(n):
        #print(DP)
        if i != mid:
            for p in range(k-1, -1, -1):
                if p-A[i] >= 0:
                    DP[p] = int(DP[p-A[i]] or DP[p])
        # print(j)
    need = 0
    #print(DP)
    for p in range(max(0, k-A[mid]), k):
        if DP[p] == 1:
            need = 1
    
    if need == 1:
        ri = mid
    else:
        le = mid
    mid = (le + ri) // 2

print(le + 1)

Fixed submission:
n, k = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
# print(A)
A_set = list(set(A))

A_set = [int(i) for i in A_set]
A_set.sort()

#print(A_set)

le = -1
ri = len(A_set)
mid = (le + ri) // 2

while ri - le > 1:
    need = 0
    # print(le,ri,mid)

    DP = [0 for i in range(k)]
    DP[0] = 1
    jogai = 0
    for i in range(n):
        #print(DP)
        if jogai == 0 and A[i] == A_set[mid]:
            jogai = 1
        else:
            for p in range(k-1, A[i]-1, -1):
                DP[p] = int(DP[p-A[i]] or DP[p])
            # print(j)
    
            #print(DP)
        for p in range(max(0, k-A_set[mid]), k):
            if DP[p] == 1:
                need = 1
                break
        if need == 1:
            break
    
    if need == 1:
        ri = mid
    else:
        le = mid
    mid = (le + ri) // 2


ans = 0

if le != -1:
    jougen = A_set[le]
    for i in range(n):
        if A[i] <= jougen:
            ans += 1

print(ans)