Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] = a[i - 1] + a[i]

for i in range(1, m + 1):
    b[i] = b[i - 1] + b[i]
ans = 0
t = 0
j = 0
for i in range(n + 1):
    while j < m + 1 and k - a[i] >= b[j]:
        j += 1
    j -= 1
    ans = max(ans, i + j)

print(ans)


Fixed submission:
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while j > 0 and k - A[i] < B[j]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] = a[i - 1] + a[i]

for i in range(1, m + 1):
    b[i] = b[i - 1] + b[i]
ans = 0
t = 0
j = m
for i in range(n + 1):
    while k - a[i] < b[j] and j > 0:
        j -= 1
    if k - a[i] >= b[j]:
        ans = max(ans, j + i)
    j = m

print(ans)


Fixed submission:
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while j > 0 and k - A[i] < B[j]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = [0]+list(map(int, input().split()))
b = [0]+list(map(int, input().split()))
for i in range(1,n+1):
    a[i]= a[i-1]+ a[i]

for i in range(1,m+1):
    b[i]= b[i-1]+ b[i]

ans = 0
t = 0
for i in range(n + 1):
    for j in range(m + 1):
        if a[i] + b[j] <= k:
            ans = max(ans, i + j)
        else:
            break
print(ans)


Fixed submission:
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while j > 0 and k - A[i] < B[j]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [0] + [sum(a[:i + 1]) for i in range(n)]
b = [0] + [sum(b[:i + 1]) for i in range(m)]
ans = 0
t = 0
for i in range(n + 1):
    for j in range(m + 1):
        if a[i] + b[j] <= k:
            ans = max(ans, i + j)
        else:
            break
print(ans)


Fixed submission:
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while j > 0 and k - A[i] < B[j]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque

import numpy as np

n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))


def bfs():
    d = ((1, 0), (0, 1))
    maze = [[0] * (m + 1) for _ in range(n + 1)]
    q = deque([])
    q.append((0, 0))
    maze[0][0] = k
    while q:
        x, y = q.popleft()
        if maze[x][y] < 0:
            for i in range(x, n + 1):
                for j in range(y, m + 1):
                    maze[i][j] = -1
        for i in range(2):
            nx = x + d[i][0]
            ny = y + d[i][1]
            if 0 <= nx <= n and 0 <= ny <= m and maze[nx][ny] == 0:
                q.append((nx, ny))
                maze[nx][ny] = maze[x][y] - a[nx] * d[i][0] - b[ny] * d[i][1]
    o = np.array(maze)
    o = np.argwhere(o >= 0)
    return max(sum(i) for i in o)


print(bfs())


Fixed submission:
#!/usr/bin/env python3
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while j > 0 and k - A[i] < B[j]:
        j -= 1
    ans = max(ans, i + j)

print(ans)