# 解説



def main():

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

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

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



    def accumulate(a):

        s = 0

        yield s

        for x in a:

            s += x

            yield s



    A = accumulate(A)

    *B, = accumulate(B)



    ans = 0

    j = M



    for i, x in enumerate(A):

        if x > K: break

        while B[j] > K - x: j -= 1

        ans = max(ans, i + j)



    print(ans)





if __name__ == '__main__':

    main()

def main():

    from itertools import chain



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

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

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



    t = sum(B)

    ans = 0

    j = M

    for i, x in enumerate(chain([0], A)):

        t += x

        while j > 0 and t > K:

            j -= 1

            t -= B[j]

        if t > K: break

        if ans < i + j:

            ans = i + j

    print(ans)





if __name__ == '__main__':

    main()

# 解説
def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    A = accumulate(A)
    (*B,) = accumulate(B)
    ans = 0
    j = M
    for i, x in enumerate(A):
        if x > K:
            break
        while B[j] > K - x:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    from itertools import chain

    N, M, K = list(map(int, input().split()))
    (*A,) = list(map(int, input().split()))
    (*B,) = list(map(int, input().split()))
    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K:
            break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == "__main__":
    main()

-# 解説 +    from itertools import chain + -    A = list(map(int, input().split())) -    B = list(map(int, input().split())) - -    def accumulate(a): -        s = 0 -        yield s -        for x in a: -            s += x -            yield s - -    A = accumulate(A) -    (*B,) = accumulate(B) +    (*A,) = list(map(int, input().split())) +    (*B,) = list(map(int, input().split())) +    t = sum(B) -    for i, x in enumerate(A): -        if x > K: +    for i, x in enumerate(chain([0], A)): +        t += x +        while j > 0 and t > K: +            j -= 1 +            t -= B[j] +        if t > K: -        while B[j] > K - x: -            j -= 1 -        ans = max(ans, i + j) +        if ans < i + j: +            ans = i + j