import numpy as np





def main():

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

    A = np.array([0] + [int(i) for i in input().split()])

    B = np.array([0] + [int(i) for i in input().split()])



    A.cumsum(out=A)

    B.cumsum(out=B)



    ans = 0

    j = M

    for i in range(N + 1):

        if A[i] > K:

            break

        while B[j] + A[i] > K:

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



    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)





if __name__ == '__main__':

    main()
import numpy as np


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


if __name__ == "__main__":
    main()

-import numpy as np - - -    A = np.array([0] + [int(i) for i in input().split()]) -    B = np.array([0] + [int(i) for i in input().split()]) -    A.cumsum(out=A) -    B.cumsum(out=B) -    ans = 0 -    j = M +    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 -        if A[i] > K: +        if a[i] > K: -        while B[j] + A[i] > K: +        while b[j] > K - a[i]: