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

sum_A = [0]
for  i in range(N):
    sum_A.append(sum_A[i] + A[i])

sum_B = [0]
for  i in range(M):
    sum_B.append(sum_B[i] + B[i])

ans = 0
s = 0

for i in range (N + 1):
    for j in range(M + 1):
        s = sum_A[i] + sum_B[j]
        if s <= K:
            ans = max(ans, i + j)
        else:
            break

print(ans)


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

sum_A = [0]
for  i in range(N):
    sum_A.append(sum_A[i] + A[i])

sum_B = [0]
for  i in range(M):
    sum_B.append(sum_B[i] + B[i])

ans = 0
j = M

for i in range (N+1):
    if sum_A[i] > K:
        break
    while sum_B[j] > K - sum_A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for n in range(N):
    A[n] = int(A[n])
for m in range(M):
    B[m] = int(B[m])
Ka = 0
ca = 0
for a in range (N):
    if Ka + A[a] <= K:
        Ka += A[a]
        ca += 1
    else:
        break
Kb = 0
cb= 0
for b in range (M):
    if Kb + B[b] <= K:
        Kb += B[b]
        cb += 1
    else:
        break
list_c = [ca, cb]
for i in range (1, ca+1):
    for j in range (1, cb+1):
        c = i + j
        s = 0
        for a in range (i):
            s += A[a]
        for b in range (j):
            s += B[b]
        if s <= K:
            list_c.append(c)
list_c.sort()
print(list_c[len(list_c) - 1])


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

sum_A = [0]
for  i in range(N):
    sum_A.append(sum_A[i] + A[i])

sum_B = [0]
for  i in range(M):
    sum_B.append(sum_B[i] + B[i])

ans = 0
j = M

for i in range (N+1):
    if sum_A[i] > K:
        break
    while sum_B[j] > K - sum_A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for n in range(N):
    A[n] = int(A[n])
for m in range(M):
    B[m] = int(B[m])
Ka = 0
ca = 0
for a in range (N):
    if Ka + A[a] <= K:
        Ka += A[a]
        ca += 1
    else:
        break
Kb = 0
cb= 0
for b in range (M):
    if Kb + B[b] <= K:
        Kb += B[b]
        cb += 1
    else:
        break
list_c = [ca, cb]
for i in range (1, ca+1):
    for j in range (1, cb+1):
        c = i + j
        s = 0
        for a in range (i):
            s += A[a]
        for b in range (j):
            s += B[b]
        if s <= K:
            list_c.append(c)
list_c.sort()
print(list_c[len(list_c) - 1])

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

sum_A = [0]
for  i in range(N):
    sum_A.append(sum_A[i] + A[i])

sum_B = [0]
for  i in range(M):
    sum_B.append(sum_B[i] + B[i])

ans = 0
j = M

for i in range (N+1):
    if sum_A[i] > K:
        break
    while sum_B[j] > K - sum_A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)