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()))

aa = [0]
bb = [0]

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

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

ans = 0
flag = 0
for i in range(n+1):
    if k - aa[i] < 0:
        flag = 1
        break
    for j in range(m+1):
        if k - aa[i] - bb[j] < 0:
            flag =1
            break
    if ans < i + j - 1:
        ans = i + j - 1


if flag == 0:
    print(i+j)
    exit()
print(ans)


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]
bb = [0]

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

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

ans = 0
mstart = m
for i in range(n+1):
    if k - aa[i] < 0:
        break
    for j in range(mstart,-1,-1):
        if k - aa[i] - bb[j] >= 0:
            mstart = j
            break
    if ans < i + j :
        ans = i + j 

print(ans)

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()))

aa = [0]
bb = [0]

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

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

ans = 0
flag = 0
for i in range(n+1):
    if k - aa[i] < 0:
        flag = 1
        if ans < i-1:
            ans = i-1   
        break
    for j in range(m+1):
        if k - aa[i] - bb[j] < 0:
            flag = 1
            if ans < i + j - 1:
                ans = i + j - 1
            break

if flag == 0:
    print(n+m)
    exit()
print(ans)


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]
bb = [0]

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

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

ans = 0
mstart = m
for i in range(n+1):
    if k - aa[i] < 0:
        break
    for j in range(mstart,-1,-1):
        if k - aa[i] - bb[j] >= 0:
            mstart = j
            break
    if ans < i + j :
        ans = i + j 

print(ans)

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()))

aa = [0]*(n+1)
bb = [0]*(m+1)

for i in range(n):
    aa[i+1] = a[i] + aa[i]

for i in range(m):
    bb[i+1] = b[i] + bb[i]

ans = 0
flag = 0
for i in range(n+1):
    if k - aa[i] < 0:
        flag = 1
        if ans < i-1:
            ans = i-1   
        break
    for j in range(m+1):
        if k - aa[i] - bb[j] < 0:
            flag = 1
            if ans < i + j - 1:
                ans = i + j - 1
            break

if flag == 0:
    print(n+m)
    exit()
print(ans)


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]
bb = [0]

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

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

ans = 0
mstart = m
for i in range(n+1):
    if k - aa[i] < 0:
        break
    for j in range(mstart,-1,-1):
        if k - aa[i] - bb[j] >= 0:
            mstart = j
            break
    if ans < i + j :
        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()))

cnt = 0
n_a = 0
n_b = 0

while True:
    if n_a < n and n_b < m:
        if a[n_a] < b[n_b]:
            k = k-a[n_a]
            if k >= 0:
                n_a = n_a + 1
                cnt = cnt + 1
            else:
                print(cnt)
                exit()
        else:
            k = k - b[n_b]
            if k >= 0:
                n_b = n_b + 1
                cnt = cnt + 1
            else:
                print(cnt)
                exit()
    elif n_a < n:
        k = k - a[n_b]
        if k >= 0:
            n_a = n_a + 1
            cnt = cnt + 1
        else:
            print(cnt)
            exit()
    elif n_b < m:
        k = k - b[n_b]
        if k >= 0:
            n_b = n_b + 1
            cnt = cnt + 1
        else:
            print(cnt)
            exit()
    else:
        print(cnt)
        exit()
       

    


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]
bb = [0]

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

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

ans = 0
mstart = m
for i in range(n+1):
    if k - aa[i] < 0:
        break
    for j in range(mstart,-1,-1):
        if k - aa[i] - bb[j] >= 0:
            mstart = j
            break
    if ans < i + j :
        ans = i + j 

print(ans)