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

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

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



a, b = [0], [0]

for i in range(N):

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

for i in range(M):

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



ans, j = 0, 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 itertools import accumulate

import bisect



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

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

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



SA = [0] + list(accumulate(A))

SB = [0] + list(accumulate(B))



max_count = 0

for i in range(N + 1):

    a_count = i

    b_count = bisect.bisect_right(SB, K - SA[a_count]) - 1

    if b_count >= 0:

        count = a_count + b_count

        if count > max_count:

            max_count = count

        

print(max_count)
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, 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 itertools import accumulate
import bisect

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] + list(accumulate(A))
SB = [0] + list(accumulate(B))
max_count = 0
for i in range(N + 1):
    a_count = i
    b_count = bisect.bisect_right(SB, K - SA[a_count]) - 1
    if b_count >= 0:
        count = a_count + b_count
        if count > max_count:
            max_count = count
print(max_count)

+from itertools import accumulate +import bisect + -a, b = [0], [0] -for i in range(N): -    a.append(a[i] + A[i]) -for i in range(M): -    b.append(b[i] + B[i]) -ans, j = 0, M +SA = [0] + list(accumulate(A)) +SB = [0] + list(accumulate(B)) +max_count = 0 -    if a[i] > K: -        break -    while b[j] > K - a[i]: -        j -= 1 -    ans = max(ans, i + j) -print(ans) +    a_count = i +    b_count = bisect.bisect_right(SB, K - SA[a_count]) - 1 +    if b_count >= 0: +        count = a_count + b_count +        if count > max_count: +            max_count = count +print(max_count)