# C - Tsundoku

from bisect import bisect

from itertools import accumulate





def main():

    N, M, K, *AB = list(map(int, open(0).read().split()))

    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:]))

    candidates = []

    for cum_x, cum_y in ((cum_A, cum_B), (cum_B, cum_A)):

        for i, x_time in enumerate(cum_x, 1):

            if x_time > K:

                candidates.append(0)

                break

            y_time = K - x_time

            candidates.append(i + bisect(cum_y, y_time))

    print((max(candidates)))





if __name__ == "__main__":

    main()

# C - Tsundoku

from bisect import bisect

from itertools import accumulate





def main():

    N, M, K, *AB = list(map(int, open(0).read().split()))

    cum_A, cum_B = tuple(accumulate([0] + AB[:N])), tuple(accumulate(AB[N:]))

    candidates = []

    for i, a_time in enumerate(cum_A):

        if a_time > K:

            candidates.append(0)

            break

        b_time = K - a_time

        candidates.append(i + bisect(cum_B, b_time))

    print((max(candidates)))





if __name__ == "__main__":

    main()

# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = list(map(int, open(0).read().split()))
    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for cum_x, cum_y in ((cum_A, cum_B), (cum_B, cum_A)):
        for i, x_time in enumerate(cum_x, 1):
            if x_time > K:
                candidates.append(0)
                break
            y_time = K - x_time
            candidates.append(i + bisect(cum_y, y_time))
    print((max(candidates)))


if __name__ == "__main__":
    main()

# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = list(map(int, open(0).read().split()))
    cum_A, cum_B = tuple(accumulate([0] + AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for i, a_time in enumerate(cum_A):
        if a_time > K:
            candidates.append(0)
            break
        b_time = K - a_time
        candidates.append(i + bisect(cum_B, b_time))
    print((max(candidates)))


if __name__ == "__main__":
    main()

-    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:])) +    cum_A, cum_B = tuple(accumulate([0] + AB[:N])), tuple(accumulate(AB[N:])) -    for cum_x, cum_y in ((cum_A, cum_B), (cum_B, cum_A)): -        for i, x_time in enumerate(cum_x, 1): -            if x_time > K: -                candidates.append(0) -                break -            y_time = K - x_time -            candidates.append(i + bisect(cum_y, y_time)) +    for i, a_time in enumerate(cum_A): +        if a_time > K: +            candidates.append(0) +            break +        b_time = K - a_time +        candidates.append(i + bisect(cum_B, b_time))