N, M, K = list(map(int, input().split()))

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

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



A, B = [0]*(N+1), [0]*(M+1)

for i in range(1, N+1):

    A[i] = A[i-1] + A_temp[i-1]

    

for j in range(1, M+1):

    B[j] = B[j-1] + B_temp[j-1]

    

ans = 0

for a in range(N+1):

    if A[a] > K:

        break

    for b in range(ans-a+1, M+1):

        if A[a] + B[b] > K:

            break

        ans = max(ans, a+b)

        

print(ans)
N, M, K = list(map(int, input().split()))

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

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



A, B = [0]*(N+1), [0]*(M+1)

for i in range(1, N+1):

    A[i] = A[i-1] + A_temp[i-1]

for i in range(1, M+1):

    B[i] = B[i-1] + B_temp[i-1]



ans = 0

b = M

for a in range(N+1):

    if A[a] > K:

        break

    while B[b] > K - A[a]:

        b -= 1

    ans = max(ans, a + b)

print(ans)
N, M, K = list(map(int, input().split()))
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]
A, B = [0] * (N + 1), [0] * (M + 1)
for i in range(1, N + 1):
    A[i] = A[i - 1] + A_temp[i - 1]
for j in range(1, M + 1):
    B[j] = B[j - 1] + B_temp[j - 1]
ans = 0
for a in range(N + 1):
    if A[a] > K:
        break
    for b in range(ans - a + 1, M + 1):
        if A[a] + B[b] > K:
            break
        ans = max(ans, a + b)
print(ans)

N, M, K = list(map(int, input().split()))
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]
A, B = [0] * (N + 1), [0] * (M + 1)
for i in range(1, N + 1):
    A[i] = A[i - 1] + A_temp[i - 1]
for i in range(1, M + 1):
    B[i] = B[i - 1] + B_temp[i - 1]
ans = 0
b = M
for a in range(N + 1):
    if A[a] > K:
        break
    while B[b] > K - A[a]:
        b -= 1
    ans = max(ans, a + b)
print(ans)

-for j in range(1, M + 1): -    B[j] = B[j - 1] + B_temp[j - 1] +for i in range(1, M + 1): +    B[i] = B[i - 1] + B_temp[i - 1] +b = M -    for b in range(ans - a + 1, M + 1): -        if A[a] + B[b] > K: -            break -        ans = max(ans, a + b) +    while B[b] > K - A[a]: +        b -= 1 +    ans = max(ans, a + b)