Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(accumulate([int(i) for i in input().split()]))
B = [0] + list(accumulate([int(i) for i in input().split()]))
ans = 0
for n in range(N+1):
    a = A[n]
    for m in reversed(range(M+1)):
        if a + B[m] <= K:
            ans = max(ans, n+m)
            break
print(ans)

Fixed submission:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(accumulate([int(i) for i in input().split()]))
B = [0] + list(accumulate([int(i) for i in input().split()]))
ans = 0
for n in range(N+1):
    a = A[n]
    for m in reversed(range(M+1)):
        if a + B[m] <= K:
            ans = max(ans, n+m)
print(ans)

Fixed submission:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
A = list(accumulate(A))
B = list(accumulate(B))
ans = 0
for n in range(N+1):
    for m in reversed(range(M+1)):
        if A[n] + B[m] <= K:
            ans = max(ans, n+m)
            break
print(ans)

Fixed submission:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(accumulate([int(i) for i in input().split()]))
B = [0] + list(accumulate([int(i) for i in input().split()]))
ans = 0
for n in range(N+1):
    for m in reversed(range(M+1)):
        if A[n] + B[m] <= K:
            ans = max(ans, n+m)
            break
print(ans)

Fixed submission:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(accumulate([int(i) for i in input().split()]))
B = [0] + list(accumulate([int(i) for i in input().split()]))
ans = 0
for n in range(N+1):
    for m in reversed(range(M+1)):
        if A[n] + B[m] <= K:
            ans = max(ans, n+m)
            break
print(ans)

Fixed submission:
import itertools
N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
SA = list(itertools.accumulate(A))
SB = list(itertools.accumulate(B))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)