from bisect import bisect_right

from time import time



N, M, K = [int(x) for x in input().split()]



a_book = [0]

for index, i in enumerate(input().split(), 1):

    if a_book[index-1] + int(i) <= K:

        a_book.append(a_book[index-1] + int(i))

    else:

        N = index - 1

        break



b_book = [0]

for index, i in enumerate(input().split(), 1):

    if b_book[index-1] + int(i) <= K:

        b_book.append(b_book[index-1] + int(i))

    else:

        M = index - 1

        break



check = {}



max_books = 0



for i, a in enumerate(a_book):

    b_pos = bisect_right(b_book, K - a)



    if max_books < b_pos - 1 + i:

        max_books = b_pos - 1 + i



print(max_books)

from bisect import bisect_right

from itertools import accumulate



N, M, K = [int(x) for x in input().split()]



a_book = [0] + list(accumulate([int(x) for x in input().split()]))

b_book = [0] + list(accumulate([int(x) for x in input().split()]))



check = {}



max_books = 0



for i, a in enumerate(a_book):

    if a > K:

        break



    b_pos = bisect_right(b_book, K - a)



    if max_books < b_pos - 1 + i:

        max_books = b_pos - 1 + i



print(max_books)

from bisect import bisect_right
from time import time

N, M, K = [int(x) for x in input().split()]
a_book = [0]
for index, i in enumerate(input().split(), 1):
    if a_book[index - 1] + int(i) <= K:
        a_book.append(a_book[index - 1] + int(i))
    else:
        N = index - 1
        break
b_book = [0]
for index, i in enumerate(input().split(), 1):
    if b_book[index - 1] + int(i) <= K:
        b_book.append(b_book[index - 1] + int(i))
    else:
        M = index - 1
        break
check = {}
max_books = 0
for i, a in enumerate(a_book):
    b_pos = bisect_right(b_book, K - a)
    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i
print(max_books)

from bisect import bisect_right
from itertools import accumulate

N, M, K = [int(x) for x in input().split()]
a_book = [0] + list(accumulate([int(x) for x in input().split()]))
b_book = [0] + list(accumulate([int(x) for x in input().split()]))
check = {}
max_books = 0
for i, a in enumerate(a_book):
    if a > K:
        break
    b_pos = bisect_right(b_book, K - a)
    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i
print(max_books)

-from time import time +from itertools import accumulate -a_book = [0] -for index, i in enumerate(input().split(), 1): -    if a_book[index - 1] + int(i) <= K: -        a_book.append(a_book[index - 1] + int(i)) -    else: -        N = index - 1 -        break -b_book = [0] -for index, i in enumerate(input().split(), 1): -    if b_book[index - 1] + int(i) <= K: -        b_book.append(b_book[index - 1] + int(i)) -    else: -        M = index - 1 -        break +a_book = [0] + list(accumulate([int(x) for x in input().split()])) +b_book = [0] + list(accumulate([int(x) for x in input().split()])) +    if a > K: +        break