Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    for j in range(0, m+1):
        if AS[i] + BS[j] > k:
            break
        ans = max(ans, i+j)
        
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
j = m
for i in range(n+1):
    if AS[i] > k:
        break

    while AS[i] + BS[j] > k:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
import numpy as np
from itertools import accumulate
AS = np.array([0] + list(accumulate(A)))
BS = np.array([0] + list(accumulate(B)))

ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    for j in range(m+1):
        if AS[i] + BS[j] > k:
            break
        ans = max(ans, i+j)
        
print(ans)



Fixed submission:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
j = m
for i in range(n+1):
    if AS[i] > k:
        break

    while AS[i] + BS[j] > k:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

from collections import deque
q = deque([[0, 0, 0]])
ans = 0
while q:
    t, ai, bi = q.pop()
    if t > k:
        continue
    ans = max(ans, ai+bi)

    if ai < n:
        q.append([t + A[ai], ai+1, bi])
    if bi < m:
        q.append([t + B[ai], ai, bi+1])

print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
j = m
for i in range(n+1):
    if AS[i] > k:
        break

    while AS[i] + BS[j] > k:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
SA = sum(A)
SB = sum(B)

if SA+SB <= k:
    print(len(A) + len(B))
else:
    t = 0
    ai = 0; bi = 0
    while True:
        if bi == m or A[ai] < B[bi]:
            t += A[ai]
            ai += 1
        else:
            t += B[bi]
            bi += 1

        if t >= k:
            break
    print(ai + bi - 1)
    

Fixed submission:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
j = m
for i in range(n+1):
    if AS[i] > k:
        break

    while AS[i] + BS[j] > k:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)