Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
import sys
sys.setrecursionlimit(10**6)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    if(k < t):
        maxc = max(maxc,cnt-1)
        return 
    if(a_i < n):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)
 
    if(b_i < m):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)
 
 
 
        
dfs(0,0,0,0)
print(maxc)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
import sys
sys.setrecursionlimit(10**6)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    if(k < t):
        maxc = max(maxc,cnt-1)
        return 
    if(a_i < n):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)

    if(b_i < m):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)



        
dfs(0,0,0,0)
print(maxc)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
import sys
sys.setrecursionlimit(10**6)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    
    if(a_i < n and (A[a_i]+t)<=k):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)
    else:
        maxc = max(cnt,maxc)
    if(b_i < m and (B[b_i]+t)<=k):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)
    else:
        maxc = max(cnt,maxc)


        
dfs(0,0,0,0)
print(maxc)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)

Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
import sys
sys.setrecursionlimit(10**5)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    
    if(a_i < n and (A[a_i]+t)<=k):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)
    else:
        maxc = max(cnt,maxc)
    if(b_i < m and (B[b_i]+t)<=k):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)
    else:
        maxc = max(cnt,maxc)


        
dfs(0,0,0,0)
print(maxc)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
import sys
sys.setrecursionlimit(10**6)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    if(a_i==n):
        if((t+B[b_i])>k):
            if(cnt > maxc):
                maxc = cnt
            return
        dfs(a_i,b_i+1,t+B[b_i],cnt+1)
        return
    if(b_i==m):
        if((t+A[a_i])>k):
            if(cnt > maxc):
                maxc = cnt
            return
        dfs(a_i+1,b_i,t+A[a_i],cnt+1)
        return
    if((A[a_i]+t)<=k):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)
    else:
        if(maxc < cnt):
            maxc = cnt
    if((B[b_i]+t)<=k):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)
    else:
        if(maxc < cnt):
            maxc = cnt

        
dfs(0,0,0,0)
print(maxc)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)

Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
lA = len(A)
lB = len(B)
a_i=0
b_i=0
cnt = 0
t = 0
while(k > t):
    if(lA==a_i and lB==b_i):
        break
    if(lA==a_i):
        t += B[b_i]
        b_i += 1
        cnt += 1
        continue
    elif(lB==a_i):
        t += A[a_i]
        a_i += 1
        cnt += 1
        continue
    else:
        if(A[a_i] > B[b_i]):
            now = B[b_i]
            b_i += 1
        else:
            now = A[a_i]
            a_i += 1
        t += now
        cnt += 1

if(t > k):
    cnt -= 1
print(cnt)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)