from collections import deque

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 itertools import accumulate

from bisect import bisect

n,m,k=list(map(int,input().split()))

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

A=list(accumulate(A,initial=0))

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

B=list(accumulate(B))



ans = 0

for i,a in enumerate(A):

  if a > k: break

  ans = max(ans,i + bisect(B,k-a))

print(ans)
from collections import deque

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 itertools import accumulate
from bisect import bisect

n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list(accumulate(A, initial=0))
B = list(map(int, input().split()))
B = list(accumulate(B))
ans = 0
for i, a in enumerate(A):
    if a > k:
        break
    ans = max(ans, i + bisect(B, k - a))
print(ans)

-from collections import deque +from itertools import accumulate +from bisect import bisect +A = list(accumulate(A, initial=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 -for i in range(n + 1): -    if a[i] > k: +B = list(accumulate(B)) +ans = 0 +for i, a in enumerate(A): +    if a > k: -    while b[j] > k - a[i]: -        j -= 1 -    ans = max(ans, i + j) +    ans = max(ans, i + bisect(B, k - a))