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

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

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



sumA = [0] * (N+1)

sumB = [0] * (M+1)

for i in range(N):

    sumA[i+1] = sumA[i] + A[i]

for i in range(M):

    sumB[i+1] = sumB[i] + B[i]



ans = 0

import bisect

for i in range(N+1):

    if K - sumA[i] >= 0:

        idx = bisect.bisect_right(sumB,K-sumA[i])

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

#         print(idx-1)

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

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

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



from itertools import accumulate

import bisect



sum_a_list = list(accumulate([0] + a_list))

sum_b_list = list(accumulate([0] + b_list))



ans = 0

b_idx = 0

for a_idx in range(n+1):

    if sum_a_list[a_idx] > k:

        continue



    time_rest = k - sum_a_list[a_idx]

    b_idx = bisect.bisect_right(sum_b_list,time_rest)



    ans = max(ans, a_idx + b_idx - 1)



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

for i in range(N + 1):
    if K - sumA[i] >= 0:
        idx = bisect.bisect_right(sumB, K - sumA[i])
        ans = max(ans, i + idx - 1)
#         print(idx-1)
print(ans)

n, m, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))
ans = 0
b_idx = 0
for a_idx in range(n + 1):
    if sum_a_list[a_idx] > k:
        continue
    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_right(sum_b_list, time_rest)
    ans = max(ans, a_idx + b_idx - 1)
print(ans)

-N, M, K = list(map(int, input().split())) -A = list(map(int, input().split())) -B = list(map(int, input().split())) -sumA = [0] * (N + 1) -sumB = [0] * (M + 1) -for i in range(N): -    sumA[i + 1] = sumA[i] + A[i] -for i in range(M): -    sumB[i + 1] = sumB[i] + B[i] -ans = 0 +n, m, k = list(map(int, input().split())) +a_list = list(map(int, input().split())) +b_list = list(map(int, input().split())) +from itertools import accumulate -for i in range(N + 1): -    if K - sumA[i] >= 0: -        idx = bisect.bisect_right(sumB, K - sumA[i]) -        ans = max(ans, i + idx - 1) -#         print(idx-1) +sum_a_list = list(accumulate([0] + a_list)) +sum_b_list = list(accumulate([0] + b_list)) +ans = 0 +b_idx = 0 +for a_idx in range(n + 1): +    if sum_a_list[a_idx] > k: +        continue +    time_rest = k - sum_a_list[a_idx] +    b_idx = bisect.bisect_right(sum_b_list, time_rest) +    ans = max(ans, a_idx + b_idx - 1)