import random
while 1:
    n,t=random.randint(1,10),random.randint(1,100)
    m=1
    A=[random.randint(1,100) for _ in range(n)]
    C=[random.randint(1,n) for _ in range(m)]
    M=m
    C.sort()
    F=[0]*(n+1)
    for i in range(n):
        F[i+1]=F[i]+A[i]
    Q=[]
    z=0
    w=C[0]-1
    for c in C:
        i=c-1
        while Q and Q[0]<i:
            Q.pop(0)
        l,r=i,n
        while l<r-1:
            m=(l+r)//2
            if F[m+1]-F[i]<=t:
                l=m
            else:
                r=m
        for j in range(max(w,i),l+1):
            while Q and (((t-(F[Q[-1]]-F[i]))//A[Q[-1]])<((t-(F[j]-F[i]))//A[j])):
                Q.pop(-1)
            Q.append(j)
            w=j+1
        
        j=Q[0]
        z=max(z,j-i+((t-(F[j]-F[i]))//A[j]))
    C=list(reversed(C))
    for i in range(M):
        C[i]=n-C[i]+1
    A=list(reversed(A))
    F=[0]*(n+1)
    for i in range(n):
        F[i+1]=F[i]+A[i]
    Q=[]
    w=C[0]-1
    for c in C:
        i=c-1
        while Q and Q[0]<i:
            Q.pop(0)
        l,r=i,n
        while l<r-1:
            m=(l+r)//2
            if F[m+1]-F[i]<=t:
                l=m
            else:
                r=m
        for j in range(max(w,i),l+1):
            while Q and (((t-(F[Q[-1]]-F[i]))//A[Q[-1]])<((t-(F[j]-F[i]))//A[j])):
                Q.pop(-1)
            Q.append(j)
            w=j+1
        j=Q[0]
        z=max(z,j-i+((t-(F[j]-F[i]))//A[j]))

    
    ans1=z
    m=M
    A=list(reversed(A))
    for i in range(M):
        C[i]=n-C[i]+1
    dp=[[0]*(t+1) for _ in range(n+2)]
    z=0
    for c in C:
        if A[c-1]<=t:
            dp[c][A[c-1]]=1
            z=max(z,1)
    for j in range(t+1):
        for i in range(1,n+1):
            if j>=A[i-1]:
                q=max([dp[i-1][j-A[i-1]],dp[i+1][j-A[i-1]],dp[i][j-A[i-1]]])
                if q>0:
                    q+=1
                    dp[i][j]=q
                    z=max(z,q)
    ans2=z
    if ans1!=ans2:
        print(ans1,ans2)
        print(n,m,t)
        print(A)
        print(C)
        break
        
