from bisect import bisect

from collections import deque



N,M,K = list(map(int,input().split()))

A = list(map(int,input().split()))

B = list(map(int,input().split()))



csumA = [0]

csumB = [0]



s = 0

for i in A:

    s += i

    csumA.append(s)

s = 0

for i in B:

    s += i

    csumB.append(s)



ans = 0

for i in range(N+1):

    if K - csumA[i] >= 0:

        ##print(i,i+bisect(csumB,max(0,K-csumA[i])))

        ans = max(ans,i-1+bisect(csumB,max(0,K-csumA[i])))



for i in range(M+1):

    if K - csumB[i] >= 0:

        ans = max(ans,i-1+bisect(csumA,max(0,K-csumB[i])))



print(ans)

    
N, M, K = list(map(int, input().split()))

A = list(map(int, input().split()))

B = list(map(int, input().split()))

 

a, b = [0], [0]

for i in range(N):

  a.append(a[i] + A[i])

for i in range(M):

  b.append(b[i] + B[i])

 

ans, j = 0, M

for i in range(N + 1):

  if a[i] > K:

    break

  while b[j] > K - a[i]:

    j -= 1

  ans = max(ans, i + j)

print(ans)
from bisect import bisect
from collections import deque

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
csumA = [0]
csumB = [0]
s = 0
for i in A:
    s += i
    csumA.append(s)
s = 0
for i in B:
    s += i
    csumB.append(s)
ans = 0
for i in range(N + 1):
    if K - csumA[i] >= 0:
        ##print(i,i+bisect(csumB,max(0,K-csumA[i])))
        ans = max(ans, i - 1 + bisect(csumB, max(0, K - csumA[i])))
for i in range(M + 1):
    if K - csumB[i] >= 0:
        ans = max(ans, i - 1 + bisect(csumA, max(0, K - csumB[i])))
print(ans)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

-from bisect import bisect -from collections import deque - -csumA = [0] -csumB = [0] -s = 0 -for i in A: -    s += i -    csumA.append(s) -s = 0 -for i in B: -    s += i -    csumB.append(s) -ans = 0 +a, b = [0], [0] +for i in range(N): +    a.append(a[i] + A[i]) +for i in range(M): +    b.append(b[i] + B[i]) +ans, j = 0, M -    if K - csumA[i] >= 0: -        ##print(i,i+bisect(csumB,max(0,K-csumA[i]))) -        ans = max(ans, i - 1 + bisect(csumB, max(0, K - csumA[i]))) -for i in range(M + 1): -    if K - csumB[i] >= 0: -        ans = max(ans, i - 1 + bisect(csumA, max(0, K - csumB[i]))) +    if a[i] > K: +        break +    while b[j] > K - a[i]: +        j -= 1 +    ans = max(ans, i + j)