Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    j = M
    while j < M + 1:
        b = BS[j]
        if a + b <= K:
            if max < i + j:
                max = i + j
            break
        j -= 1

print(max)

Fixed submission:
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j
        j += 1

print(max)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b <= K and max < i + j:
            max = i + j
        j += 1

print(max)

Fixed submission:
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j
        j += 1

print(max)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(len(AS)):
    a = AS[i]
    if a > K:
        continue
    for j in range(len(BS)):
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j

print(max)

Fixed submission:
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j
        j += 1

print(max)