import bisect



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

a = [int(x) for x in input().split()]

b = [int(x) for x in input().split()]



da = [0 for _ in range(N+1)]

for i in range(N):

    da[i+1] = da[i] + a[i]

db = [0 for _ in range(M+1)]

for i in range(M):

    db[i+1] = db[i] + b[i]



ans = 0

for i in range(N+1):

    if da[i] > K:

        break

    ans = max(ans, i + bisect.bisect_right(db, K-da[i]) - 1)

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

a = [int(x) for x in input().split()]

b = [int(x) for x in input().split()]



da = [0 for _ in range(N+1)]

for i in range(N):

    da[i+1] = da[i] + a[i]

db = [0 for _ in range(M+1)]

for i in range(M):

    db[i+1] = db[i] + b[i]



ans = 0; j = M

for i in range(N+1):

    if da[i] > K:

        break

    while db[j] > K - da[i]:

        j -= 1

    ans = max(ans, i + j)

print(ans)
import bisect

N, M, K = list(map(int, input().split()))
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
da = [0 for _ in range(N + 1)]
for i in range(N):
    da[i + 1] = da[i] + a[i]
db = [0 for _ in range(M + 1)]
for i in range(M):
    db[i + 1] = db[i] + b[i]
ans = 0
for i in range(N + 1):
    if da[i] > K:
        break
    ans = max(ans, i + bisect.bisect_right(db, K - da[i]) - 1)
print(ans)

N, M, K = list(map(int, input().split()))
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
da = [0 for _ in range(N + 1)]
for i in range(N):
    da[i + 1] = da[i] + a[i]
db = [0 for _ in range(M + 1)]
for i in range(M):
    db[i + 1] = db[i] + b[i]
ans = 0
j = M
for i in range(N + 1):
    if da[i] > K:
        break
    while db[j] > K - da[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

-import bisect - +j = M -    ans = max(ans, i + bisect.bisect_right(db, K - da[i]) - 1) +    while db[j] > K - da[i]: +        j -= 1 +    ans = max(ans, i + j)