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()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    j = min_idx
    while j < len(B) and K - A[i] - B[j + 1] >= 0:
        j += 1
    if K - A[i] - B[j] >= 0:
        r = max(r, i + j)
print(r)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    j = min_idx
    while j + 1 < len(B) and K - A[i] - B[j + 1] >= 0:
        j += 1
    if K - A[i] - B[j] >= 0:
        r = max(r, i + j)
print(r)

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()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    while K - A[i] - B[j + 1] >= 0:
        j += 1
    k = K - A[i] - B[j]
    if k >= 0:
        r = max(r, i + j)
print(r)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    j = min_idx
    while j + 1 < len(B) and K - A[i] - B[j + 1] >= 0:
        j += 1
    if K - A[i] - B[j] >= 0:
        r = max(r, i + j)
print(r)

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()))
memo = [[None] * (M + 1) for _ in range(N + 1)]
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    for j, b in enumerate(B):
        k = K - a - b
        if k < 0:
            break
        r = max(r, i + j)
print(r)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    j = min_idx
    while j + 1 < len(B) and K - A[i] - B[j + 1] >= 0:
        j += 1
    if K - A[i] - B[j] >= 0:
        r = max(r, i + j)
print(r)

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()))
memo = [[None] * (M + 1) for _ in range(N + 1)]
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
K = [[K - a - b for b in B] for a in A]
def solution(i=0, j=0):
    if i > N or j > M:
        return -1
    if memo[i][j] is not None:
        return memo[i][j]
    if K[i][j] == 0:
        memo[i][j] = 0
        return 0
    elif K[i][j] < 0:
        memo[i][j] = -1
        return -1
    memo[i][j] = 1 + max(
        solution(i + 1, j),
        solution(i, j + 1))
    return memo[i][j]
print(solution())

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    j = min_idx
    while j + 1 < len(B) and K - A[i] - B[j + 1] >= 0:
        j += 1
    if K - A[i] - B[j] >= 0:
        r = max(r, i + j)
print(r)