from itertools import accumulate

from bisect import bisect_right

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



def main():

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

    A = [int(i) for i in readline().split()]

    B = [int(i) for i in readline().split()]



    acc_A = list(accumulate(A))

    acc_B = list(accumulate(B))



    ans = 0

    for i, a in enumerate(acc_A):

        tmp = i + 1

        rest = K - a

        if rest < 0:

            ans = max(ans, bisect_right(acc_B, K))

            break

        b_ind = bisect_right(acc_B, rest)

        tmp += b_ind



        ans = max(ans, tmp)



    for i, b in enumerate(acc_B):

        tmp = i + 1

        rest = K - b

        if rest < 0:

            ans = max(ans, bisect_right(acc_A, K))

            break

        a_ind = bisect_right(acc_A, rest)

        tmp += a_ind



        ans = max(ans, tmp)

    

    print(ans)

       





if __name__ == "__main__":

    main()

from itertools import accumulate

from bisect import bisect_right

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



def main():

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

    A = [int(i) for i in readline().split()]

    B = [int(i) for i in readline().split()]



    acc_A = [0] + list(accumulate(A))

    acc_B = [0] + list(accumulate(B))



    ans = 0

    for i, a in enumerate(acc_A):

        tmp = i

        rest = K - a

        if rest < 0:

            ans = max(ans, bisect_right(acc_B, K) - 1)

            break

        b_ind = bisect_right(acc_B, rest) - 1

        tmp += b_ind



        ans = max(ans, tmp)

   

    print(ans)

       





if __name__ == "__main__":

    main()

from itertools import accumulate
from bisect import bisect_right
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, M, K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    acc_A = list(accumulate(A))
    acc_B = list(accumulate(B))
    ans = 0
    for i, a in enumerate(acc_A):
        tmp = i + 1
        rest = K - a
        if rest < 0:
            ans = max(ans, bisect_right(acc_B, K))
            break
        b_ind = bisect_right(acc_B, rest)
        tmp += b_ind
        ans = max(ans, tmp)
    for i, b in enumerate(acc_B):
        tmp = i + 1
        rest = K - b
        if rest < 0:
            ans = max(ans, bisect_right(acc_A, K))
            break
        a_ind = bisect_right(acc_A, rest)
        tmp += a_ind
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

from itertools import accumulate
from bisect import bisect_right
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, M, K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    acc_A = [0] + list(accumulate(A))
    acc_B = [0] + list(accumulate(B))
    ans = 0
    for i, a in enumerate(acc_A):
        tmp = i
        rest = K - a
        if rest < 0:
            ans = max(ans, bisect_right(acc_B, K) - 1)
            break
        b_ind = bisect_right(acc_B, rest) - 1
        tmp += b_ind
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

-    acc_A = list(accumulate(A)) -    acc_B = list(accumulate(B)) +    acc_A = [0] + list(accumulate(A)) +    acc_B = [0] + list(accumulate(B)) -        tmp = i + 1 +        tmp = i -            ans = max(ans, bisect_right(acc_B, K)) +            ans = max(ans, bisect_right(acc_B, K) - 1) -        b_ind = bisect_right(acc_B, rest) +        b_ind = bisect_right(acc_B, rest) - 1 -        ans = max(ans, tmp) -    for i, b in enumerate(acc_B): -        tmp = i + 1 -        rest = K - b -        if rest < 0: -            ans = max(ans, bisect_right(acc_A, K)) -            break -        a_ind = bisect_right(acc_A, rest) -        tmp += a_ind