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

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')

n, m, k = rm()
a = rl()
b = rl()

cnt = 0
lena = len(a)
lenb = len(b)
dp = [[inf]*(lenb + 1) for _ in range(lena + 1)]
dp[0][0] = 0
dp[0][1] = b[0]
dp[1][0] = a[0]

for i in range(lena):
    for j in range(lenb):
        dp[i][j+1] = dp[i][j] + b[j]
        dp[i+1][j] = dp[i][j] + a[i]
        if dp[i][j+1] <= k or dp[i+1][j] <= k:
            cnt = max(i+j+1, cnt)
        else:
            break
else:
    if dp[lena][lenb-1] + b[lenb-1] <= k:
        cnt += 1
print(cnt)











Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
if a[0] > k:
    ans = 0
else:
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k:
            right = j
        else:
            left = j
    ans = left + 1
t = 0
b0 = b[0]
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    if b0 > k-t:
        ans = max(ans, cnt)
        continue
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 1)
print(ans)

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

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')

n, m, k = rm()
a = rl()
b = rl()

cnt = 0
lena = len(a)
lenb = len(b)
dp = [[inf]*(lenb + 1) for _ in range(lena + 1)]
dp[0][0] = 0
dp[0][1] = b[0]
dp[1][0] = a[0]

for i in range(lena):
    for j in range(lenb):
        dp[i][j+1] = dp[i][j] + b[j]
        dp[i+1][j] = dp[i][j] + a[i]
        if dp[i][j+1] <= k or dp[i+1][j] <= k:
            cnt = max(i+j+1, cnt)
else:
    if dp[lena][lenb-1] + b[lenb-1] <= k:
        cnt += 1
print(cnt)











Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
if a[0] > k:
    ans = 0
else:
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k:
            right = j
        else:
            left = j
    ans = left + 1
t = 0
b0 = b[0]
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    if b0 > k-t:
        ans = max(ans, cnt)
        continue
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 1)
print(ans)