Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
ans=N
D=[[False]*K for i in range(N+1)]
D[N][0]=True
for i in range(N-1,-1,-1):
    D[i][0]=True
    if A[i]>=K:
        ans=i
        continue
    else:
        for k in range(K):
            if D[i+1][k]:
                if K-A[i]<=k:
                    ans=i
                D[i][k]=True
                if k+A[i]<K:
                    D[i][k+A[i]]=True
print(ans)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
ans=0
for a in A:
    if S+a<K:
        S+=a
        ans+=1
    else:ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
A=[a for a in A if a<K]
from collections import defaultdict
N=len(A)
bord=-1
can={0}
now=0
for i in range(N):
    flag=False
    canc=can.copy()
    for x in canc:
        if K-A[i]<=x<K:
            flag=True
        if x+A[i]<K:
            can|={x+A[i]}
    if flag:
        bord=i
print(N-bord-1)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
ans=0
for a in A:
    if S+a<K:
        S+=a
        ans+=1
    else:ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
A=[a for a in A if a<K]
from collections import defaultdict
N=len(A)
bord=-1
can={0}
now=0
for i in range(N):
    flag=False
    for j in range(K-A[i],K):
        if j in can:
            flag=True
            break
    if flag:
        bord=i
    canc=can.copy()
    for x in canc:
        if x+A[i]<K:
            can|={x+A[i]}
print(N-bord-1)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
ans=0
for a in A:
    if S+a<K:
        S+=a
        ans+=1
    else:ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
import bisect
idx=bisect.bisect_left(A,K)
ans=0
A=A[:idx]
N=idx
from collections import defaultdict
def search(i):
    dp=defaultdict(int)
    dp[0]=1
    ai=A[i]
    for j in range(N):
        dpc=dp.copy()
        if i==j:continue
        for k in dpc.keys():
            if k+A[j]>=K or dpc[k]==0:
                continue
            if k+A[j]>=K-ai:
                return True
            dp[k+A[j]]=1
    return False
MinTrue=N
MaxFalse=-1
check=(1,2)
while MinTrue-MaxFalse>1:
    idx=N*check[0]//check[1]
    if search(idx):
        MinTrue=min(MinTrue,idx)
        check=(check[0]*2-1,check[1]*2)
    else:
        MaxFalse=max(MaxFalse,idx)
        check=(check[0]*2+1,check[1]*2)
print(MinTrue)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
ans=0
for a in A:
    if S+a<K:
        S+=a
        ans+=1
    else:ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
def DP(N,K,A,i):
    Ac=A.copy()
    a_check=Ac.pop(i)
    if a_check>=K:
        return True
    dp=[0]*(K-a_check+1)
    dp[0]=1
    for a in Ac:
        dpc=dp.copy()
        for k in range(K-a_check+1):
            if dpc[k]==0:continue
            else:
                if k+a<K-a_check:
                    dp[k+a]=1
                elif K-a_check<=k+a<K:
                    return True
    return False

def bisect(N,K,A,check,maxFalse,minTrue):
    idx=N*check[0]//check[1]
    if DP(N,K,A,idx)==True:
        if maxFalse==idx-1:
            return maxFalse
        return bisect(N,K,A,(check[0]*2-1,check[1]*2),maxFalse,min(minTrue,idx))
    else:
        if minTrue==idx+1:
            return idx
        return bisect(N,K,A,(check[0]*2+1,check[1]*2),max(maxFalse,idx),minTrue)

print(bisect(N,K,A,(1,2),-1,N)+1)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
ans=0
for a in A:
    if S+a<K:
        S+=a
        ans+=1
    else:ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in range(N):
    a=A[i]
    if a>=K:
        cnt+=1
        continue
    Ac=A.copy()
    Ac.pop(i)
    dp=[0]*(K-a+1)
    dp[0]=1
    for b in Ac:
        dpc=dp.copy()
        for k in range(K-a+1):
            if k+b>=K:break
            if k+b<K-a:
                dp[k+b]+=dpc[k]
            elif k+b>=K-a:
                dp[K-a]+=dpc[k]
        if dp[K-a]>0:
            cnt+=1
            break
print(N-cnt)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
ans=0
for a in A:
    if S+a<K:
        S+=a
        ans+=1
    else:ans=0
print(ans)