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

dp=[[0 for j in range(K+1)] for i in range(max(N,M)+1)]
if(N<M):
    ma=M
    mi=N
    turn='M'
else:
    ma=N
    mi=M
    turn='N'

if(turn=='M'):
    for i in range(ma):
        for j in range(K+1):
            if(mi<=i):
                if(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
            else:

                if(A[i]<j and B[i]<j):

                    dp[i+1][j]=max(dp[i][j-A[i]-B[i]]+2,dp[i][j])

                elif(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                elif(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
else:
    for i in range(ma):
        for j in range(K+1):
            if(mi<=i):
                if(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
            else:
                if(A[i]<j and B[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]-B[i]]+2,dp[i][j])

                elif(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                elif(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]

print(dp[ma][K])


Fixed submission:
N,M,K=map(int,input().split())
A=[]
B=[]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0 for i in range(len(A)+1)]
for i in range(1,len(A)+1):
    a[i]=a[i-1]+A[i-1]

b=[0 for i in range(len(B)+1)]
for i in range(1,len(B)+1):
    b[i]=b[i-1]+B[i-1]

j=M
ans=0
for i in range(len(A)+1):

    if(K<a[i]):
        break
    #print(a[i]+b[j])
    while(a[i]+b[j]>K):
        j=j-1
    ans=max(ans,i+j)

print(ans)

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

dp=[[0 for j in range(K)] for i in range(max(N,M))]
if(N<M):
    ma=M
    mi=N
    turn='M'
else:
    ma=N
    mi=M
    turn='N'

if(turn='M')
    for i in range(nn):
        for j in range(K+1):
            if(mi<i):
                if(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
            else:
                if(A[i]<j and B[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]-B[i]]+2,dp[i][j])

                elif(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]+1,dp[i][j]])
                elif(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
else:
    for i in range(nn):
        for j in range(K+1):
            if(mi<i):
                if(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]
            else:
                if(A[i]<j and B[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]-B[i]]+2,dp[i][j])

                elif(A[i]<j):
                    dp[i+1][j]=max(dp[i][j-A[i]+1,dp[i][j]])
                elif(B[i]<j):
                    dp[i+1][j]=max(dp[i][j-B[i]]+1,dp[i][j])
                else:
                    dp[i+1][j]=dp[i][j]

print(dp[nn][K])


Fixed submission:
N,M,K=map(int,input().split())
A=[]
B=[]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0 for i in range(len(A)+1)]
for i in range(1,len(A)+1):
    a[i]=a[i-1]+A[i-1]

b=[0 for i in range(len(B)+1)]
for i in range(1,len(B)+1):
    b[i]=b[i-1]+B[i-1]

j=M
ans=0
for i in range(len(A)+1):

    if(K<a[i]):
        break
    #print(a[i]+b[j])
    while(a[i]+b[j]>K):
        j=j-1
    ans=max(ans,i+j)

print(ans)