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

max_num = 0
j = 0
j_max = M
# A_sums=[0]
# B_sums=[0]
# for i in range(N):
#     A_sums.append(A_sums[i]+A[i])
# for i in range(M):
#     B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if sum(A[:i])>K:
        break
    while sum(A[:i]) + sum(B[:j_max]) > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)


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

max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while A_sums[i]+B_sums[j_max] > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)

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

max_num = 0
j = 0
j_max = M + 1
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while j < j_max:
        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)


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

max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while A_sums[i]+B_sums[j_max] > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)

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

max_num = 0
j = 0
j_max = M + 1
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    while j < j_max:

        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)


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

max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while A_sums[i]+B_sums[j_max] > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)

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

max_num = 0
j = 0
j_max = M + 1
A_sums=[sum(A[:i]) for i in range(N+1)]
B_sums=[sum(B[:i]) for i in range(M+1)]

for i in range(N + 1):
    j = 0
    while j < j_max:

        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)


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

max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while A_sums[i]+B_sums[j_max] > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)

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

max_num = 0
j = 0
j_max = M + 1
for i in range(N + 1):
    j = 0
    while j < j_max:
        if sum(A[:i]) + sum(B[:j]) > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)


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

max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while A_sums[i]+B_sums[j_max] > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)