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

#k = int(input())

import bisect

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

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

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

#al=[list(input()) for i in range(h)]

acum = [0]

for i in range(n):

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



bcum = [0]

for i in range(m):

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

ans = 0

for i in range(n+1):

    rsd = k-acum[i]

    if rsd < 0:

        break

    #if rsd == 0:

    #    ans = max(ans, i)

    #    continue

    ind = bisect.bisect_right(bcum, rsd)

    ans = max(ans, i+ind-1)

print(ans)

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

# k = int(input())
import bisect

n, m, k = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
# al=[list(input()) for i in range(h)]
acum = [0]
for i in range(n):
    acum.append(al[i] + acum[i])
bcum = [0]
for i in range(m):
    bcum.append(bl[i] + bcum[i])
ans = 0
for i in range(n + 1):
    rsd = k - acum[i]
    if rsd < 0:
        break
    # if rsd == 0:
    #    ans = max(ans, i)
    #    continue
    ind = bisect.bisect_right(bcum, rsd)
    ans = max(ans, i + ind - 1)
print(ans)

-# n=int(input()) +# k = int(input()) +import bisect + -# l=[list(map(int,input().split())) for i in range(n)] -import bisect - -A = [0] +# al=[list(input()) for i in range(h)] +acum = [0] -    A.append(A[i] + al[i]) -B = [0] +    acum.append(al[i] + acum[i]) +bcum = [0] -    B.append(B[i] + bl[i]) -# B.append(max(B[m],k)+1) -mx = 0 +    bcum.append(bl[i] + bcum[i]) +ans = 0 -    rem = k - A[i] -    if rem < 0: -        continue -    bnum = bisect.bisect_right(B, rem) - 1 -    mx = max(mx, i + bnum) -print(mx) +    rsd = k - acum[i] +    if rsd < 0: +        break +    # if rsd == 0: +    #    ans = max(ans, i) +    #    continue +    ind = bisect.bisect_right(bcum, rsd) +    ans = max(ans, i + ind - 1) +print(ans)