from bisect import bisect_right



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

a = [int(i) for i in input().split()]

b = [int(i) for i in input().split()]

A = [0]

B = [0]

for i in range(n):

    A.append(A[-1] + a[i])

for j in range(m):

    B.append(B[-1] + b[j])

    

ans = 0

for i in range(n + 1):

    time = A[i]

    b_index = 0

    if time > k:

        break

    b_index = bisect_right(B, k - time)

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

print(ans)
from bisect import bisect_right



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

a = [int(i) for i in input().split()]

b = [int(i) for i in input().split()]

A = [0]

B = [0]

for i in range(n):

    A.append(A[-1] + a[i])

for j in range(m):

    B.append(B[-1] + b[j])

    

ans = 0

j = m

for i in range(n + 1):

    if A[i] > k:

        break

    while B[j] > k - A[i]:

        j -= 1

    ans = max(ans, i + j)

print(ans)
from bisect import bisect_right

n, m, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [0]
B = [0]
for i in range(n):
    A.append(A[-1] + a[i])
for j in range(m):
    B.append(B[-1] + b[j])
ans = 0
for i in range(n + 1):
    time = A[i]
    b_index = 0
    if time > k:
        break
    b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

from bisect import bisect_right

n, m, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [0]
B = [0]
for i in range(n):
    A.append(A[-1] + a[i])
for j in range(m):
    B.append(B[-1] + b[j])
ans = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while B[j] > k - A[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

+j = m -    time = A[i] -    b_index = 0 -    if time > k: +    if A[i] > k: -    b_index = bisect_right(B, k - time) -    ans = max(ans, i + b_index - 1) +    while B[j] > k - A[i]: +        j -= 1 +    ans = max(ans, i + j)