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

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

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

cuma = [0]

cumb  = [0]

for a in A:

    cuma.append(cuma[-1] + a)

for b in B:

    cumb.append(cumb[-1] + b)

from bisect import bisect_left

ans = 0

for i in range(n+1):

    if k < cuma[i]: continue

    idx = bisect_left(cumb, k - cuma[i] + 1)

    ans = max(ans, i + idx - 1)

for j in range(m+1):

    if k < cumb[j]: continue

    idx = bisect_left(cuma, k - cumb[j] + 1)

    ans = max(ans, j + idx - 1)

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

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

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

cuma = [0]

cumb  = [0]

for a in A:

    cuma.append(cuma[-1] + a)

for b in B:

    cumb.append(cumb[-1] + b)

from bisect import bisect_left

ans = 0

for i in range(n+1):

    if k < cuma[i]: break

    idx = bisect_left(cumb, k - cuma[i] + 1)

    ans = max(ans, i + idx - 1)

print(ans)
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cuma = [0]
cumb = [0]
for a in A:
    cuma.append(cuma[-1] + a)
for b in B:
    cumb.append(cumb[-1] + b)
from bisect import bisect_left

ans = 0
for i in range(n + 1):
    if k < cuma[i]:
        continue
    idx = bisect_left(cumb, k - cuma[i] + 1)
    ans = max(ans, i + idx - 1)
for j in range(m + 1):
    if k < cumb[j]:
        continue
    idx = bisect_left(cuma, k - cumb[j] + 1)
    ans = max(ans, j + idx - 1)
print(ans)

n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cuma = [0]
cumb = [0]
for a in A:
    cuma.append(cuma[-1] + a)
for b in B:
    cumb.append(cumb[-1] + b)
from bisect import bisect_left

ans = 0
for i in range(n + 1):
    if k < cuma[i]:
        break
    idx = bisect_left(cumb, k - cuma[i] + 1)
    ans = max(ans, i + idx - 1)
print(ans)

-        continue +        break -for j in range(m + 1): -    if k < cumb[j]: -        continue -    idx = bisect_left(cuma, k - cumb[j] + 1) -    ans = max(ans, j + idx - 1)