import bisect



#　入力

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



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

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



# A,Bの累積和を取る

sumA = [0]*(n+1)

sumB = [0]*(m+1)

for i in range(n):

    sumA[i+1] = sumA[i] + A[i]

for i in range(m):

    sumB[i+1] = sumB[i] + B[i]





ans = 0

# 二分探索

for i,a in enumerate(sumA):

    if a > k:break

    j = bisect.bisect_right(sumB,k-a)

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

print(ans)

#　入力

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



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

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



# A,Bの累積和を取る

sumA = [0]*(n+1)

sumB = [0]*(m+1)

for i in range(n):

    sumA[i+1] = sumA[i] + A[i]

for i in range(m):

    sumB[i+1] = sumB[i] + B[i]



ans = 0

# しゃくとり法

j = m

for i,a in enumerate(sumA):

    while j >= 0 and a + sumB[j] > k:

        j -= 1

    if j < 0:break

    ans = max(ans,i+j)

print(ans)

import bisect

# 　入力
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# A,Bの累積和を取る
sumA = [0] * (n + 1)
sumB = [0] * (m + 1)
for i in range(n):
    sumA[i + 1] = sumA[i] + A[i]
for i in range(m):
    sumB[i + 1] = sumB[i] + B[i]
ans = 0
# 二分探索
for i, a in enumerate(sumA):
    if a > k:
        break
    j = bisect.bisect_right(sumB, k - a)
    ans = max(i + j - 1, ans)
print(ans)

# 　入力
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# A,Bの累積和を取る
sumA = [0] * (n + 1)
sumB = [0] * (m + 1)
for i in range(n):
    sumA[i + 1] = sumA[i] + A[i]
for i in range(m):
    sumB[i + 1] = sumB[i] + B[i]
ans = 0
# しゃくとり法
j = m
for i, a in enumerate(sumA):
    while j >= 0 and a + sumB[j] > k:
        j -= 1
    if j < 0:
        break
    ans = max(ans, i + j)
print(ans)

-import bisect - -# 二分探索 +# しゃくとり法 +j = m -    if a > k: +    while j >= 0 and a + sumB[j] > k: +        j -= 1 +    if j < 0: -    j = bisect.bisect_right(sumB, k - a) -    ans = max(i + j - 1, ans) +    ans = max(ans, i + j)