N, M, K = list(map(int, input().split()))

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

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



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



ans, j = 0, M

for i in range(N + 1):

    if a[i] > K:

        break

    while b[j] > K - a[i]:

        j -= 1

    ans = max(ans, i + j)

print(ans)

import itertools as it

def main():

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

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

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

    a, b = [0],[0]

    for i in range(n):

        a.append(a[i] + Aa[i])

    for i in range(m):

        b.append(b[i] + Bb[i])

    M = m

    ans = 0

    for A in range(n+1):

        aa = a[A]

        Kaa = k-aa

        if Kaa < 0:

            break

        for B in range(M,-1,-1):

            if b[B] <= Kaa:

                ans = max(ans, A+B)

                M = B

                break

    print(ans)



if __name__ == '__main__':

    main()
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
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])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

import itertools as it


def main():
    n, m, k = list(map(int, input().split()))
    Aa = list(map(int, input().split()))
    Bb = list(map(int, input().split()))
    a, b = [0], [0]
    for i in range(n):
        a.append(a[i] + Aa[i])
    for i in range(m):
        b.append(b[i] + Bb[i])
    M = m
    ans = 0
    for A in range(n + 1):
        aa = a[A]
        Kaa = k - aa
        if Kaa < 0:
            break
        for B in range(M, -1, -1):
            if b[B] <= Kaa:
                ans = max(ans, A + B)
                M = B
                break
    print(ans)


if __name__ == "__main__":
    main()

-N, M, K = list(map(int, input().split())) -A = list(map(int, input().split())) -B = list(map(int, input().split())) -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]) -ans, j = 0, M -for i in range(N + 1): -    if a[i] > K: -        break -    while b[j] > K - a[i]: -        j -= 1 -    ans = max(ans, i + j) -print(ans) +import itertools as it + + +def main(): +    n, m, k = list(map(int, input().split())) +    Aa = list(map(int, input().split())) +    Bb = list(map(int, input().split())) +    a, b = [0], [0] +    for i in range(n): +        a.append(a[i] + Aa[i]) +    for i in range(m): +        b.append(b[i] + Bb[i]) +    M = m +    ans = 0 +    for A in range(n + 1): +        aa = a[A] +        Kaa = k - aa +        if Kaa < 0: +            break +        for B in range(M, -1, -1): +            if b[B] <= Kaa: +                ans = max(ans, A + B) +                M = B +                break +    print(ans) + + +if __name__ == "__main__": +    main()