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

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

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

A_sum = [0]

for i in range(N):

    A_sum.append(A[i] + A_sum[i])

B_sum = [0]

for i in range(M):

    B_sum.append(B[i] + B_sum[i])    

import bisect

ans = 0

for i in range(N+1):

    a = A_sum[i]

    if K-a >=0:

        b_idx = bisect.bisect(B_sum, K-a) - 1

        if b_idx  < 0:

            b_idx = 0

        ans = max(ans, i+b_idx)

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

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

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

A_sum = [0]

for i in range(N):

    A_sum.append(A[i] + A_sum[i])

B_sum = [0]

for i in range(M):

    B_sum.append(B[i] + B_sum[i])   

    

b_idx = 0

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

    if B_sum[i] <= K:

        b_idx = i

ans = 0

for i in range(N+1):

    if b_idx > 0:

        while A_sum[i] + B_sum[b_idx] > K:

            b_idx -= 1

            if b_idx < 0:

                b_idx = 0

                break

    if A_sum[i] + B_sum[b_idx] <= K:

        ans = max(ans, i+b_idx)

print(ans)
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])
import bisect

ans = 0
for i in range(N + 1):
    a = A_sum[i]
    if K - a >= 0:
        b_idx = bisect.bisect(B_sum, K - a) - 1
        if b_idx < 0:
            b_idx = 0
        ans = max(ans, i + b_idx)
print(ans)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])
b_idx = 0
for i in range(1, M + 1):
    if B_sum[i] <= K:
        b_idx = i
ans = 0
for i in range(N + 1):
    if b_idx > 0:
        while A_sum[i] + B_sum[b_idx] > K:
            b_idx -= 1
            if b_idx < 0:
                b_idx = 0
                break
    if A_sum[i] + B_sum[b_idx] <= K:
        ans = max(ans, i + b_idx)
print(ans)

-import bisect - +b_idx = 0 +for i in range(1, M + 1): +    if B_sum[i] <= K: +        b_idx = i -    a = A_sum[i] -    if K - a >= 0: -        b_idx = bisect.bisect(B_sum, K - a) - 1 -        if b_idx < 0: -            b_idx = 0 +    if b_idx > 0: +        while A_sum[i] + B_sum[b_idx] > K: +            b_idx -= 1 +            if b_idx < 0: +                b_idx = 0 +                break +    if A_sum[i] + B_sum[b_idx] <= K: