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_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

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

max_num = 0
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        break

    for j in range(M, -1, -1):
        if (A_cost + B_accumulate_cost[j] <= K):
            if (i + j > max_num):
                max_num = i+j
            break

print(max_num)

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

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

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

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

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

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

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

max_num = 0
for i in range(N, -1, -1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        continue

    for j in range(M, -1, -1):
        if (A_cost + B_accumulate_cost[j] <= K):
            if (i + j > max_num):
                max_num = i+j
            break

print(max_num)

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

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

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

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

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

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)
    if(lastCost > K):
        break

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)
    if(lastCost > K):
        break

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(0,N+1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        break

    for j in range(0,M+1):
        if (A_cost + B_accumulate_cost[j] > K):
            break

        if( i+j > max_num):
            max_num = i+j

print(max_num)

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

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

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

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

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

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

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

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

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(0,N+1):
    if (A_accumulate_cost[i] > K):
        break

    for j in range(0,M+1):
        if (A_accumulate_cost[i] + B_accumulate_cost[j] > K):
            break

        if( i+j > max_num):
            max_num = i+j

print(max_num)

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

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

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

max_num = 0
p = M
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if A_cost > K:
        break

    for j in range(p, -1, -1):
        if A_cost + B_accumulate_cost[j] <= K:
            p = j
            if i + j > max_num:
                max_num = i+j
            break

print(max_num)