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

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

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



A_sum=[0,A[0]]

B_sum=[0,B[0]]

for i in range(1,N):

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

for i in range(1,M):

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



b_read=0

ans=0

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

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

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

            ans=max(ans,i+j)

            b_read=j

        else:

            break

print(ans)

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

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

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

import bisect

A_sum=[0]

B_sum=[0]

for i in range(N):

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

for i in range(M):

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



ans=0

for i in range(N+1):

    if A_sum[i]>K:

        continue

    b_read=bisect.bisect_right(B_sum,K-A_sum[i])-1

    ans=max(ans,i+b_read)

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, A[0]]
B_sum = [0, B[0]]
for i in range(1, N):
    A_sum.append(A_sum[i] + A[i])
for i in range(1, M):
    B_sum.append(B_sum[i] + B[i])
b_read = 0
ans = 0
for i in range(N, -1, -1):
    for j in range(b_read, M + 1):
        if A_sum[i] + B_sum[j] <= K:
            ans = max(ans, i + j)
            b_read = j
        else:
            break
print(ans)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
import bisect

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i] + A[i])
for i in range(M):
    B_sum.append(B_sum[i] + B[i])
ans = 0
for i in range(N + 1):
    if A_sum[i] > K:
        continue
    b_read = bisect.bisect_right(B_sum, K - A_sum[i]) - 1
    ans = max(ans, i + b_read)
print(ans)

-A_sum = [0, A[0]] -B_sum = [0, B[0]] -for i in range(1, N): +import bisect + +A_sum = [0] +B_sum = [0] +for i in range(N): -for i in range(1, M): +for i in range(M): -b_read = 0 -for i in range(N, -1, -1): -    for j in range(b_read, M + 1): -        if A_sum[i] + B_sum[j] <= K: -            ans = max(ans, i + j) -            b_read = j -        else: -            break +for i in range(N + 1): +    if A_sum[i] > K: +        continue +    b_read = bisect.bisect_right(B_sum, K - A_sum[i]) - 1 +    ans = max(ans, i + b_read)