#n=int(input())

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

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

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

#l=[list(map(int,input().split())) for i in range(n)]



A=[0]

for i in range(n):

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

B=[0]

for i in range(m):

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

B.append(max(B[m],k)+1)

mx=0

for i in range(n+1):

    rem=k-A[i]

    if rem<0:

        continue

    left=0;right=m+1

    while right-left>1:

        mid=(left+right)//2

        if B[mid]>rem:

            right=mid

        else:

            left=mid

    mx=max(left+i,mx)



print(mx)

#n=int(input())

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

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

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

#l=[list(map(int,input().split())) for i in range(n)]

import bisect

A=[0]

for i in range(n):

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

B=[0]

for i in range(m):

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

#B.append(max(B[m],k)+1)

mx=0

for i in range(n+1):

    rem=k-A[i]

    if rem<0:

        continue

    bnum=bisect.bisect_right(B,rem)-1

    mx=max(mx,i+bnum)



print(mx)

# n=int(input())
n, m, k = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
A = [0]
for i in range(n):
    A.append(A[i] + al[i])
B = [0]
for i in range(m):
    B.append(B[i] + bl[i])
B.append(max(B[m], k) + 1)
mx = 0
for i in range(n + 1):
    rem = k - A[i]
    if rem < 0:
        continue
    left = 0
    right = m + 1
    while right - left > 1:
        mid = (left + right) // 2
        if B[mid] > rem:
            right = mid
        else:
            left = mid
    mx = max(left + i, mx)
print(mx)

# n=int(input())
n, m, k = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
import bisect

A = [0]
for i in range(n):
    A.append(A[i] + al[i])
B = [0]
for i in range(m):
    B.append(B[i] + bl[i])
# B.append(max(B[m],k)+1)
mx = 0
for i in range(n + 1):
    rem = k - A[i]
    if rem < 0:
        continue
    bnum = bisect.bisect_right(B, rem) - 1
    mx = max(mx, i + bnum)
print(mx)

+import bisect + -B.append(max(B[m], k) + 1) +# B.append(max(B[m],k)+1) -    left = 0 -    right = m + 1 -    while right - left > 1: -        mid = (left + right) // 2 -        if B[mid] > rem: -            right = mid -        else: -            left = mid -    mx = max(left + i, mx) +    bnum = bisect.bisect_right(B, rem) - 1 +    mx = max(mx, i + bnum)