import bisect

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

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

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

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])



for j in range(n+1):

  K=k-A[j]

  if K<0:

    break

  else:

    ans=max(ans,bisect.bisect_right(B,K)+j-1)

print(ans)

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

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

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

ans,right=0,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])

for i in range(m+1):

  if k<B[i] or i==m:

    right=i-1

    if i==m:

      right=i

    ans=right

    break



for j in range(0,n):

  if k<a[j]:

    break

  k-=a[j]

  while k<B[right]:

    right-=1

  ans=max(ans,right+j+1)

print(ans)
import bisect

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
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])
for j in range(n + 1):
    K = k - A[j]
    if K < 0:
        break
    else:
        ans = max(ans, bisect.bisect_right(B, K) + j - 1)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans, right = 0, 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])
for i in range(m + 1):
    if k < B[i] or i == m:
        right = i - 1
        if i == m:
            right = i
        ans = right
        break
for j in range(0, n):
    if k < a[j]:
        break
    k -= a[j]
    while k < B[right]:
        right -= 1
    ans = max(ans, right + j + 1)
print(ans)

-import bisect - -ans = 0 +ans, right = 0, 0 -for j in range(n + 1): -    K = k - A[j] -    if K < 0: +for i in range(m + 1): +    if k < B[i] or i == m: +        right = i - 1 +        if i == m: +            right = i +        ans = right -    else: -        ans = max(ans, bisect.bisect_right(B, K) + j - 1) +for j in range(0, n): +    if k < a[j]: +        break +    k -= a[j] +    while k < B[right]: +        right -= 1 +    ans = max(ans, right + j + 1)