import sys

from itertools import accumulate

from bisect import bisect_right



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

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

    A = AB[:N]

    B = AB[N:]



    time_A = [0]

    time_A.extend(accumulate(A))



    time_B = [0]

    time_B.extend(accumulate(B))



    ans = 0

    for i in range(N + 1):

        tmp = i

        ta = time_A[i]

        if ta <= K:

            tb = K - ta

            j = bisect_right(time_B, tb)

            tmp += j - 1



            if ans < tmp:

                ans = tmp



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys

from itertools import accumulate

from bisect import bisect_right



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

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

    A = AB[:N]

    B = AB[N:]



    time_A = [0]

    time_A.extend(accumulate(A))



    time_B = [0]

    time_B.extend(accumulate(B))



    ans = 0

    j = M

    for i, ta in enumerate(time_A):

        while j > 0 and ta + time_B[j] > K:

            j -= 1



        if ta + time_B[j] > K:

            break



        if ans < i + j:

            ans = i + j



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys
from itertools import accumulate
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, K, *AB = list(map(int, read().split()))
    A = AB[:N]
    B = AB[N:]
    time_A = [0]
    time_A.extend(accumulate(A))
    time_B = [0]
    time_B.extend(accumulate(B))
    ans = 0
    for i in range(N + 1):
        tmp = i
        ta = time_A[i]
        if ta <= K:
            tb = K - ta
            j = bisect_right(time_B, tb)
            tmp += j - 1
            if ans < tmp:
                ans = tmp
    print(ans)
    return


if __name__ == "__main__":
    main()

import sys
from itertools import accumulate
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, K, *AB = list(map(int, read().split()))
    A = AB[:N]
    B = AB[N:]
    time_A = [0]
    time_A.extend(accumulate(A))
    time_B = [0]
    time_B.extend(accumulate(B))
    ans = 0
    j = M
    for i, ta in enumerate(time_A):
        while j > 0 and ta + time_B[j] > K:
            j -= 1
        if ta + time_B[j] > K:
            break
        if ans < i + j:
            ans = i + j
    print(ans)
    return


if __name__ == "__main__":
    main()

-    for i in range(N + 1): -        tmp = i -        ta = time_A[i] -        if ta <= K: -            tb = K - ta -            j = bisect_right(time_B, tb) -            tmp += j - 1 -            if ans < tmp: -                ans = tmp +    j = M +    for i, ta in enumerate(time_A): +        while j > 0 and ta + time_B[j] > K: +            j -= 1 +        if ta + time_B[j] > K: +            break +        if ans < i + j: +            ans = i + j