def main():

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

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

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



    s = 0

    j = 0

    while j < len(B) and s + B[j] <= K:

        s += B[j]

        j += 1



    ans = cnt = j



    j -= 1

    for x in A:

        while j >= 0 and s + x > K:

            s -= B[j]

            j -= 1

            cnt -= 1

        if s + x > K:

            break

        s += x

        cnt += 1

        if ans < cnt:

            ans = cnt

    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():
    N, M, K = list(map(int, input().split()))
    (*A,) = list(map(int, input().split()))
    (*B,) = list(map(int, input().split()))
    s = 0
    j = 0
    while j < len(B) and s + B[j] <= K:
        s += B[j]
        j += 1
    ans = cnt = j
    j -= 1
    for x in A:
        while j >= 0 and s + x > K:
            s -= B[j]
            j -= 1
            cnt -= 1
        if s + x > K:
            break
        s += x
        cnt += 1
        if ans < cnt:
            ans = cnt
    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()

+# 解説 -    (*A,) = list(map(int, input().split())) -    (*B,) = list(map(int, input().split())) -    s = 0 -    j = 0 -    while j < len(B) and s + B[j] <= K: -        s += B[j] -        j += 1 -    ans = cnt = j -    j -= 1 -    for x in A: -        while j >= 0 and s + x > K: -            s -= B[j] +    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: -            cnt -= 1 -        if s + x > K: -            break -        s += x -        cnt += 1 -        if ans < cnt: -            ans = cnt +        ans = max(ans, i + j)