Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

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

ai = 0
bi = 0

def read(ai, bi, count, rest):
    if rest <= 0:
        return count
    else:
        if ai >= N:
            a_c = count
        else:
            if rest >= A[ai]:
                a_c = read(ai+1, bi, count+1, rest - A[ai])
            else:
                a_c = count

        if bi >= M:
            b_c = count
        else:
            if rest >= B[bi]:
                b_c = read(ai, bi+1, count+1, rest - B[bi])
            else:
                b_c = count

        return max(a_c, b_c)

res = read(ai,bi,0,K)
print(res)


Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumA = [0] * (N+1)
cumB = [0] * (M+1)

point = 0
for i in range(N):
    cumA[i+1] = cumA[i] + A[i]
for i in range(M):
    cumB[i+1] = cumB[i] + B[i]

# 尺取りの要領でiを増やしjを減らす
res, j = 0, M
for i in range(N+1):
    if cumA[i] > K:
        break
    while cumB[j] > K - cumA[i]:
        j -= 1
    res = max(res, i+j)

print(res)

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

ai = 0
bi = 0

def read(ai, bi, count, rest):
    if rest <= 0:
        return count
    else:
        if ai >= N:
            a_c = count
        else:
            if rest >= A[ai]:
                a_c = read(ai+1, bi, count+1, rest - A[ai])
            else:
                a_c = count

        if bi >= M:
            b_c = count
        else:
            if rest >= B[bi]:
                b_c = read(ai, bi+1, count+1, rest - B[bi])
            else:
                b_c = count

        return max(a_c, b_c)

res = read(ai,bi,0,K)
print(res)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumA = [0] * (N+1)
cumB = [0] * (M+1)

point = 0
for i in range(N):
    cumA[i+1] = cumA[i] + A[i]
for i in range(M):
    cumB[i+1] = cumB[i] + B[i]

# 尺取りの要領でiを増やしjを減らす
res, j = 0, M
for i in range(N+1):
    if cumA[i] > K:
        break
    while cumB[j] > K - cumA[i]:
        j -= 1
    res = max(res, i+j)

print(res)

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

ai = 0
bi = 0

def read(ai, bi, count, rest):
    if rest <= 0:
        return count
    else:
        if ai >= N:
            a_c = count
        elif rest >= A[ai]:
            a_c = read(ai+1, bi, count+1, rest - A[ai])
        else:
            a_c = count

        if bi >= M:
            b_c = count
        elif rest >= B[bi]:
            b_c = read(ai, bi+1, count+1, rest - B[bi])
        else:
            b_c = count

        return max(a_c, b_c)

res = read(ai,bi,0,K)
print(res)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumA = [0] * (N+1)
cumB = [0] * (M+1)

point = 0
for i in range(N):
    cumA[i+1] = cumA[i] + A[i]
for i in range(M):
    cumB[i+1] = cumB[i] + B[i]

# 尺取りの要領でiを増やしjを減らす
res, j = 0, M
for i in range(N+1):
    if cumA[i] > K:
        break
    while cumB[j] > K - cumA[i]:
        j -= 1
    res = max(res, i+j)

print(res)