Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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


Fixed submission:
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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

Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

ans = 0
for i, va in enumerate(a):
    j = M
    while j >= 0:
        if va + b[j] > K:
            j -= 1
            continue
        ans = max(i+j, ans)
        j -= 1
print(ans)


Fixed submission:
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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

Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

acum = [0]
for x in a:
    acum += [acum[-1] + x]

total = [0] * (n+1)
ans = [0] * (n+1)
cnt = 0
for i,v in enumerate(acum):
    if v > k:
        continue
    total[i] += v
    ans[i] += i
    j = 0
    for j, vv in enumerate(b):
        if total[i] > k:
            break
        if total[i] + b[j] > k:
            break
        if j >= m:
            break

        total[i] += b[j]
        ans[i] += 1
        j += 1
    #print(acum[i], j, ans[i], total[i])
    cnt = max(cnt, ans[i])
print(cnt)



Fixed submission:
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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

Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

acum = [0]
for x in a:
    acum += [acum[-1] + x]

total = [0] * (n+1)
ans = [0] * (n+1)
cnt = 0
for i,v in enumerate(acum):
    if v > k:
        continue
    total[i] += v
    ans[i] += i
    j = 0
    for j, vv in enumerate(b):
        if total[i] > k:
            break
        if total[i] + b[j] > k:
            break
        if j >= m:
            break

        total[i] += b[j]
        ans[i] += 1
        j += 1
    #print(acum[i], j, ans[i], total[i])
    cnt = max(cnt, ans[i])
print(cnt)



Fixed submission:
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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