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

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

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



lia = [0]

lib = [0]

tmp = M

ans = 0



for i in range(N):

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

for i in range(M):

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



for i in range(N+1):

    kari = 0

    t = K - lia[i]

    kari += i



    if t<0:

        break

    elif t==0:

        ans = max(ans, i)

        break

    else:

        pass



    for j in range(tmp,-1,-1):

        if t<lib[j]:

            continue

        else:

            tmp = j

            kari += j

            ans = max(ans, kari)

            break



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

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

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



lia = [0]

lib = [0]

j = M

ans = 0



for i in range(N):

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

for i in range(M):

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



for i in range(N+1):

    if lia[i] > K:

        break



    while lib[j] > K-lia[i]:

        j -= 1

    ans = max(ans, i+j)



print(ans)
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
lia = [0]
lib = [0]
tmp = M
ans = 0
for i in range(N):
    lia.append(lia[i] + A[i])
for i in range(M):
    lib.append(lib[i] + B[i])
for i in range(N + 1):
    kari = 0
    t = K - lia[i]
    kari += i
    if t < 0:
        break
    elif t == 0:
        ans = max(ans, i)
        break
    else:
        pass
    for j in range(tmp, -1, -1):
        if t < lib[j]:
            continue
        else:
            tmp = j
            kari += j
            ans = max(ans, kari)
            break
print(ans)

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

-tmp = M +j = M -    kari = 0 -    t = K - lia[i] -    kari += i -    if t < 0: +    if lia[i] > K: -    elif t == 0: -        ans = max(ans, i) -        break -    else: -        pass -    for j in range(tmp, -1, -1): -        if t < lib[j]: -            continue -        else: -            tmp = j -            kari += j -            ans = max(ans, kari) -            break +    while lib[j] > K - lia[i]: +        j -= 1 +    ans = max(ans, i + j)