import itertools

N,M,K = list(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

pt = len(B)-1

for i,sa in enumerate(SA):

    while(pt>=0):

        if sa + SB[pt] <= K:

            ans = max(ans,i+pt)

            break

        pt-=1

print (ans)







import itertools

N,M,K = list(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)







import itertools

N, M, K = list(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
pt = len(B) - 1
for i, sa in enumerate(SA):
    while pt >= 0:
        if sa + SB[pt] <= K:
            ans = max(ans, i + pt)
            break
        pt -= 1
print(ans)

import itertools

N, M, K = list(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)

-pt = len(B) - 1 -for i, sa in enumerate(SA): -    while pt >= 0: -        if sa + SB[pt] <= K: -            ans = max(ans, i + pt) +j = len(B) - 1 +for i in range(len(SA)): +    while j >= 0: +        if SA[i] + SB[j] <= K: +            ans = max(ans, i + j) -        pt -= 1 +        j -= 1