import sys, math

input = sys.stdin.readline

rs = lambda: input().strip()

ri = lambda: int(eval(input()))

rl = lambda: list(map(int, input().split()))

mod = 10**9 + 7



N, M, K = rl()

A = rl()

B = rl()



s = 0

for i, b in enumerate(B):

	s += b

	B[i] = s



import bisect



ans = 0

s = 0

j = bisect.bisect_right(B, K)

ans = j

for i, a in enumerate(A):

	s += a

	if s > K:

		break

	j = bisect.bisect_right(B, K-s)

	#print(i, j)

	n = i+1 + j

	ans = max(ans, n)

print(ans)

import sys, math

input = sys.stdin.readline

rs = lambda: input().strip()

ri = lambda: int(eval(input()))

rl = lambda: list(map(int, input().split()))

mod = 10**9 + 7



N, M, K = rl()



A = rl()

B = rl()



s = 0

j = 0

for i, b in enumerate(B):

	if s+b > K:

		break

	s += b

	j += 1



ans = j

j -= 1

for i, a in enumerate(A):

	s += a

	while j >= 0 and s > K :

		s -= B[j]

		j -= 1

	if s > K: break

	ans = max(ans, i+1+j+1)

print(ans)



import sys, math

input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
N, M, K = rl()
A = rl()
B = rl()
s = 0
for i, b in enumerate(B):
    s += b
    B[i] = s
import bisect

ans = 0
s = 0
j = bisect.bisect_right(B, K)
ans = j
for i, a in enumerate(A):
    s += a
    if s > K:
        break
    j = bisect.bisect_right(B, K - s)
    # print(i, j)
    n = i + 1 + j
    ans = max(ans, n)
print(ans)

import sys, math

input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
N, M, K = rl()
A = rl()
B = rl()
s = 0
j = 0
for i, b in enumerate(B):
    if s + b > K:
        break
    s += b
    j += 1
ans = j
j -= 1
for i, a in enumerate(A):
    s += a
    while j >= 0 and s > K:
        s -= B[j]
        j -= 1
    if s > K:
        break
    ans = max(ans, i + 1 + j + 1)
print(ans)

+j = 0 +    if s + b > K: +        break -    B[i] = s -import bisect - -ans = 0 -s = 0 -j = bisect.bisect_right(B, K) +    j += 1 +j -= 1 +    while j >= 0 and s > K: +        s -= B[j] +        j -= 1 -    j = bisect.bisect_right(B, K - s) -    # print(i, j) -    n = i + 1 + j -    ans = max(ans, n) +    ans = max(ans, i + 1 + j + 1)