from itertools import chain





def solve():

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



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

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



    answer = 0



    sum_b = sum(B)

    idx_b = M

    remain = K



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

        remain -= a

        if remain < 0:

            break



        while sum_b > remain:

            if idx_b < 0:

                break

            idx_b -= 1

            b = B[idx_b]

            sum_b -= b



        answer = max(answer, i + idx_b)



    return answer





def main():

    print((solve()))





if __name__ == "__main__":

    main()

from itertools import chain





def solve():

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



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

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



    answer = 0



    sum_b = sum(B)

    idx_b = M

    remain = K



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

        remain -= a

        if remain < 0:

            break



        while sum_b > remain and idx_b >= 0:

            idx_b -= 1

            b = B[idx_b]

            sum_b -= b

        

        i += idx_b

        answer = i if answer < i else answer



    return answer





def main():

    print((solve()))





if __name__ == "__main__":

    main()

from itertools import chain


def solve():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    answer = 0
    sum_b = sum(B)
    idx_b = M
    remain = K
    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break
        while sum_b > remain:
            if idx_b < 0:
                break
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b
        answer = max(answer, i + idx_b)
    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()

from itertools import chain


def solve():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    answer = 0
    sum_b = sum(B)
    idx_b = M
    remain = K
    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break
        while sum_b > remain and idx_b >= 0:
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b
        i += idx_b
        answer = i if answer < i else answer
    return answer


def main():
    print((solve()))


if __name__ == "__main__":
    main()

-        while sum_b > remain: -            if idx_b < 0: -                break +        while sum_b > remain and idx_b >= 0: -        answer = max(answer, i + idx_b) +        i += idx_b +        answer = i if answer < i else answer