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

a=[0]
b=[0]

ans=0

for i in range(n):
    a.append(a[i]+A[i])

for i in range(m):
    b.append(b[i]+B[i])


for i in range(0, n+1):
    if a[i]>k:
        break
    else:
        for j in range(0, m+1):
            if a[i]+b[j]>k:
                j-=1
                break
    
    ans=max(ans, i+j)


print(ans)

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

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])

for i in range(m):
    b.append(b[i]+B[i])

ans, j=0, m
for i in range(0, n+1):
    if a[i]>k:
        break
    else:
        while a[i]+b[j]>k:
            j-=1
        
    ans=max(ans, i+j)


print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))

k=tmp

ans=0

cnt1=0
cnt2=0
cost1=0
cost2=0

for i in range(n):
    cost1+=a[i]
    if cost1<=k:
        cnt1+=1
    else:
        cost1-=a[i]
        break

for j in range(m):
    cost2+=b[j]
    if cost2<=k:
        cnt2+=1
    else:
        cost2-=b[j]
        break

if cnt1>cnt2:
    ans+=cnt1
    k-=cost1
    for i in range(m):
        k-=b[i]
        if k>=0:
            ans+=1
        else:
            break
    
    print(ans)

elif cnt2>cnt1:
    ans+=cnt2
    k-=cost2
    for i in range(n):
        k-=a[i]
        if k>=0:
            ans+=1
        else:
            break
    
    print(ans)

else:
    alpha+=cnt1
    tmp-=cost1
    for i in range(m):
        tmp-=b[i]
        if k>=0:
            alpha+=1
        else:
            break
    
    bata+=cnt2
    k-=cost2
    for i in range(n):
        k-=a[i]
        if k>=0:
            bata+=1
        else:
            break

    ans=max(alpha, bata)

    print(ans)

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

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])

for i in range(m):
    b.append(b[i]+B[i])

ans, j=0, m
for i in range(0, n+1):
    if a[i]>k:
        break
    else:
        while a[i]+b[j]>k:
            j-=1
        
    ans=max(ans, i+j)


print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k=map(int, input().split())
a=list(map(int, input().split()))+[10**10]*(10**10)
b=list(map(int, input().split()))+[10**10]*(10**10)

loop=max(n, m)
i=0
j=0
T=0
ans=0

for t in range(2*loop):
    if a[i]>=b[j]:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    elif b[j]>a[i]:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()
    
    elif i==n-1:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    
    elif j==m-1:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()

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

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])

for i in range(m):
    b.append(b[i]+B[i])

ans, j=0, m
for i in range(0, n+1):
    if a[i]>k:
        break
    else:
        while a[i]+b[j]>k:
            j-=1
        
    ans=max(ans, i+j)


print(ans)