from itertools import accumulate

from bisect import bisect

def main():

    n, m, k = list(map(int, input().split()))

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

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



    aa = tuple(accumulate(a))

    ba = tuple(accumulate(b))

    r = 0

    for i1 in range(n):

        if aa[i1] > k:

            break

        else:

            t = bisect(ba, k - aa[i1])

            r = max(r, i1 + 1 + t)

    for j1 in range(m):

        if ba[j1] > k:

            break

        else:

            t = bisect(aa, k - ba[j1])

            r = max(r, j1 + 1 + t)

    print(r)

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

from itertools import accumulate

from bisect import bisect

def main():

    n, m, k = list(map(int, input().split()))

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

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



    aa = [0] + list(accumulate(a))

    ba = [0] + list(accumulate(b))

    r = 0

    for i1, aae in enumerate(aa):

        if aae > k:

            break

        else:

            time_remain = k - aae

            b_num = bisect(ba, time_remain)

            r = max(r, i1 + b_num - 1)

    print(r)



if __name__ == '__main__':

    main()
from itertools import accumulate
from bisect import bisect


def main():
    n, m, k = list(map(int, input().split()))
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))
    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1 in range(n):
        if aa[i1] > k:
            break
        else:
            t = bisect(ba, k - aa[i1])
            r = max(r, i1 + 1 + t)
    for j1 in range(m):
        if ba[j1] > k:
            break
        else:
            t = bisect(aa, k - ba[j1])
            r = max(r, j1 + 1 + t)
    print(r)


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect


def main():
    n, m, k = list(map(int, input().split()))
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))
    aa = [0] + list(accumulate(a))
    ba = [0] + list(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            r = max(r, i1 + b_num - 1)
    print(r)


if __name__ == "__main__":
    main()

+import sys + +read = sys.stdin.read +readlines = sys.stdin.readlines -    aa = tuple(accumulate(a)) -    ba = tuple(accumulate(b)) +    aa = [0] + list(accumulate(a)) +    ba = [0] + list(accumulate(b)) -    for i1 in range(n): -        if aa[i1] > k: +    for i1, aae in enumerate(aa): +        if aae > k: -            t = bisect(ba, k - aa[i1]) -            r = max(r, i1 + 1 + t) -    for j1 in range(m): -        if ba[j1] > k: -            break -        else: -            t = bisect(aa, k - ba[j1]) -            r = max(r, j1 + 1 + t) +            time_remain = k - aae +            b_num = bisect(ba, time_remain) +            r = max(r, i1 + b_num - 1)