from bisect import bisect_right





def solve():

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



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

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



    sum_as = [0] * (N+1)

    sum_bs = [0] * (M+1)



    for i, a in enumerate(A):

        sum_as[i+1] = sum_as[i] + a



    for i, b in enumerate(B):

        sum_bs[i+1] = sum_bs[i] + b

    sum_bs = sum_bs[1:]



    answer = 0

    for i, sa in enumerate(sum_as):

        remain = K - sa

        if remain < 0:

            continue

        

        idx = bisect_right(sum_bs, remain)

        answer = max(answer, i + idx)



    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 bisect import bisect_right


def solve():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    sum_as = [0] * (N + 1)
    sum_bs = [0] * (M + 1)
    for i, a in enumerate(A):
        sum_as[i + 1] = sum_as[i] + a
    for i, b in enumerate(B):
        sum_bs[i + 1] = sum_bs[i] + b
    sum_bs = sum_bs[1:]
    answer = 0
    for i, sa in enumerate(sum_as):
        remain = K - sa
        if remain < 0:
            continue
        idx = bisect_right(sum_bs, remain)
        answer = max(answer, i + idx)
    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 bisect import bisect_right +from itertools import chain -    B = list(map(int, input().split())) -    sum_as = [0] * (N + 1) -    sum_bs = [0] * (M + 1) -    for i, a in enumerate(A): -        sum_as[i + 1] = sum_as[i] + a -    for i, b in enumerate(B): -        sum_bs[i + 1] = sum_bs[i] + b -    sum_bs = sum_bs[1:] +    (*B,) = list(map(int, input().split())) -    for i, sa in enumerate(sum_as): -        remain = K - sa +    sum_b = sum(B) +    idx_b = M +    remain = K +    for i, a in enumerate(chain([0], A)): +        remain -= a -            continue -        idx = bisect_right(sum_bs, remain) -        answer = max(answer, i + idx) +            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)