import sys

from itertools import accumulate



input = sys.stdin.readline





def binary_search(a, key):

    """Meguru type binary search"""

    ok = -1

    ng = len(a)



    while (abs(ok - ng) > 1):

        mid = (ok + ng) // 2

        if a[mid] <= key:

            ok = mid

        else:

            ng = mid



    return ok





def main():

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

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

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



    B_cumsum = tuple(accumulate(B))

    ans = 0

    time = 0

    for i in range(N + 1):

        if time > K:

            break

        j = binary_search(B_cumsum, K - time) + 1

        ans = max(ans, i + j)



        if i < N:

            time += A[i]



    print(ans)





if __name__ == "__main__":

    main()

import sys

from itertools import accumulate



input = sys.stdin.readline





def binary_search(a, key):

    """Meguru type binary search"""

    ok = -1

    ng = len(a)



    while (ng - ok > 1):

        mid = (ok + ng) // 2

        if a[mid] <= key:

            ok = mid

        else:

            ng = mid



    return ok





def main():

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

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

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



    B_cumsum = tuple(accumulate(B))

    ans = 0

    time = 0

    for i in range(N + 1):

        if time > K:

            break

        j = binary_search(B_cumsum, K - time) + 1

        ans = max(ans, i + j)



        if i < N:

            time += A[i]



    print(ans)





if __name__ == "__main__":

    main()

import sys
from itertools import accumulate

input = sys.stdin.readline


def binary_search(a, key):
    """Meguru type binary search"""
    ok = -1
    ng = len(a)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if a[mid] <= key:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N, M, K = list(map(int, input().split()))
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    B_cumsum = tuple(accumulate(B))
    ans = 0
    time = 0
    for i in range(N + 1):
        if time > K:
            break
        j = binary_search(B_cumsum, K - time) + 1
        ans = max(ans, i + j)
        if i < N:
            time += A[i]
    print(ans)


if __name__ == "__main__":
    main()

import sys
from itertools import accumulate

input = sys.stdin.readline


def binary_search(a, key):
    """Meguru type binary search"""
    ok = -1
    ng = len(a)
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if a[mid] <= key:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N, M, K = list(map(int, input().split()))
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    B_cumsum = tuple(accumulate(B))
    ans = 0
    time = 0
    for i in range(N + 1):
        if time > K:
            break
        j = binary_search(B_cumsum, K - time) + 1
        ans = max(ans, i + j)
        if i < N:
            time += A[i]
    print(ans)


if __name__ == "__main__":
    main()

-    while abs(ok - ng) > 1: +    while ng - ok > 1: