from bisect import bisect_left

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

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

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



cumA=[0]*(N+1)

cumB=[0]*(M+1)



for i in range(N):

    cumA[i+1]=cumA[i]+A[i]

for i in range(M):

    cumB[i+1]=cumB[i]+B[i]



ans=0

for i in range(N+1):

    r=K-cumA[i]

    if r<0:

        break

    b=bisect_left(cumB,r)

    if b==M+1:

        ans=max(ans,i+M)

    else:

        if cumB[b]!=r:

            b-=1

        ans=max(ans,i+b)

print(ans)
def bisect(x):

    l,r=-1,M+1

    while(r-l>1):

        mid=(l+r)//2

        if cumB[mid]>=x:

            r=mid

        else:

            l=mid

    return l



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

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

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

cumB=[0]*(M+1)

for i in range(M):

    cumB[i+1]=cumB[i]+B[i]

c=0

ans=0

for i in range(N+1):

    if c>K:

        break

    r=K-c

    b=bisect(r+1)

    ans=max(ans,i+b)

    if i!=N:

        c+=A[i]

print(ans)
from bisect import bisect_left

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumA = [0] * (N + 1)
cumB = [0] * (M + 1)
for i in range(N):
    cumA[i + 1] = cumA[i] + A[i]
for i in range(M):
    cumB[i + 1] = cumB[i] + B[i]
ans = 0
for i in range(N + 1):
    r = K - cumA[i]
    if r < 0:
        break
    b = bisect_left(cumB, r)
    if b == M + 1:
        ans = max(ans, i + M)
    else:
        if cumB[b] != r:
            b -= 1
        ans = max(ans, i + b)
print(ans)

def bisect(x):
    l, r = -1, M + 1
    while r - l > 1:
        mid = (l + r) // 2
        if cumB[mid] >= x:
            r = mid
        else:
            l = mid
    return l


N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumB = [0] * (M + 1)
for i in range(M):
    cumB[i + 1] = cumB[i] + B[i]
c = 0
ans = 0
for i in range(N + 1):
    if c > K:
        break
    r = K - c
    b = bisect(r + 1)
    ans = max(ans, i + b)
    if i != N:
        c += A[i]
print(ans)

-from bisect import bisect_left +def bisect(x): +    l, r = -1, M + 1 +    while r - l > 1: +        mid = (l + r) // 2 +        if cumB[mid] >= x: +            r = mid +        else: +            l = mid +    return l + -cumA = [0] * (N + 1) -for i in range(N): -    cumA[i + 1] = cumA[i] + A[i] +c = 0 -    r = K - cumA[i] -    if r < 0: +    if c > K: -    b = bisect_left(cumB, r) -    if b == M + 1: -        ans = max(ans, i + M) -    else: -        if cumB[b] != r: -            b -= 1 -        ans = max(ans, i + b) +    r = K - c +    b = bisect(r + 1) +    ans = max(ans, i + b) +    if i != N: +        c += A[i]