from bisect import *

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

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

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

sa = [0]*(n+1)

sb = [0]*(m+1)

for i in range(n):

    sa[i+1] = sa[i] + A[i]

for i in range(m):

    sb[i+1] = sb[i] + B[i]

ans = 0

for i,a in enumerate(sa):

    if a > k:break

    will = bisect_right(sb,k-a)

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

print(ans)

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

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

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

def ruiseki(n, A):

    "長さnの数列Aの累積和を返す　ただし[0] = 0"

    res = [0]*(n+1)

    for i in range(n):

        res[i+1] = res[i] + A[i]

    return res

sa = ruiseki(n,A)

sb = ruiseki(m,B)



ans = 0

j = m

for i,a in enumerate(sa):

    

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

        j -= 1

    if j < 0:break

    ans = max(ans,i+j)

print(ans)

from bisect import *

n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
    sa[i + 1] = sa[i] + A[i]
for i in range(m):
    sb[i + 1] = sb[i] + B[i]
ans = 0
for i, a in enumerate(sa):
    if a > k:
        break
    will = bisect_right(sb, k - a)
    ans = max(i + will - 1, ans)
print(ans)

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


def ruiseki(n, A):
    "長さnの数列Aの累積和を返す　ただし[0] = 0"
    res = [0] * (n + 1)
    for i in range(n):
        res[i + 1] = res[i] + A[i]
    return res


sa = ruiseki(n, A)
sb = ruiseki(m, B)
ans = 0
j = m
for i, a in enumerate(sa):
    while j >= 0 and a + sb[j] > k:
        j -= 1
    if j < 0:
        break
    ans = max(ans, i + j)
print(ans)

-from bisect import * - -sa = [0] * (n + 1) -sb = [0] * (m + 1) -for i in range(n): -    sa[i + 1] = sa[i] + A[i] -for i in range(m): -    sb[i + 1] = sb[i] + B[i] + + +def ruiseki(n, A): +    "長さnの数列Aの累積和を返す　ただし[0] = 0" +    res = [0] * (n + 1) +    for i in range(n): +        res[i + 1] = res[i] + A[i] +    return res + + +sa = ruiseki(n, A) +sb = ruiseki(m, B) +j = m -    if a > k: +    while j >= 0 and a + sb[j] > k: +        j -= 1 +    if j < 0: -    will = bisect_right(sb, k - a) -    ans = max(i + will - 1, ans) +    ans = max(ans, i + j)