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

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

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



cnt = 0

cost = 0

for i, x in enumerate(a):

    cost += x

    if cost > k:

        cnt = i

        cost -= x

        break

else:

    for j, y in enumerate(b):

        cost += y

        if cost > k:

            cnt = n + j

            cost -= y

            break

    else:

        cnt = n + m



if cnt <= n:

    i_max, j = cnt - 1, 0

else:

    i_max, j = n - 1, cnt - n



while j < m and cost + b[j] <= k:

    cost += b[j]

    j += 1

    cnt += 1



ans = cnt

for i in range(i_max, -1, -1):

    if j == m: break

    cost -= a[i]

    cnt -= 1

    while j < m and cost + b[j] <= k:

        cost += b[j]

        j += 1

        cnt += 1



    ans = max(cnt, ans)



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

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

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



j = m - 1

cost = sum(b)

cnt = m

ans = 0

for i in range(n + 1):

    if i != 0:

        cost += a[i - 1]

        cnt += 1

    while cost > k and j >= 0:

        cost -= b[j]

        cnt -= 1

        j -= 1

    if cost <= k:

        ans = max(cnt, ans)

print(ans)
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
cost = 0
for i, x in enumerate(a):
    cost += x
    if cost > k:
        cnt = i
        cost -= x
        break
else:
    for j, y in enumerate(b):
        cost += y
        if cost > k:
            cnt = n + j
            cost -= y
            break
    else:
        cnt = n + m
if cnt <= n:
    i_max, j = cnt - 1, 0
else:
    i_max, j = n - 1, cnt - n
while j < m and cost + b[j] <= k:
    cost += b[j]
    j += 1
    cnt += 1
ans = cnt
for i in range(i_max, -1, -1):
    if j == m:
        break
    cost -= a[i]
    cnt -= 1
    while j < m and cost + b[j] <= k:
        cost += b[j]
        j += 1
        cnt += 1
    ans = max(cnt, ans)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
j = m - 1
cost = sum(b)
cnt = m
ans = 0
for i in range(n + 1):
    if i != 0:
        cost += a[i - 1]
        cnt += 1
    while cost > k and j >= 0:
        cost -= b[j]
        cnt -= 1
        j -= 1
    if cost <= k:
        ans = max(cnt, ans)
print(ans)

-cnt = 0 -cost = 0 -for i, x in enumerate(a): -    cost += x -    if cost > k: -        cnt = i -        cost -= x -        break -else: -    for j, y in enumerate(b): -        cost += y -        if cost > k: -            cnt = n + j -            cost -= y -            break -    else: -        cnt = n + m -if cnt <= n: -    i_max, j = cnt - 1, 0 -else: -    i_max, j = n - 1, cnt - n -while j < m and cost + b[j] <= k: -    cost += b[j] -    j += 1 -    cnt += 1 -ans = cnt -for i in range(i_max, -1, -1): -    if j == m: -        break -    cost -= a[i] -    cnt -= 1 -    while j < m and cost + b[j] <= k: -        cost += b[j] -        j += 1 +j = m - 1 +cost = sum(b) +cnt = m +ans = 0 +for i in range(n + 1): +    if i != 0: +        cost += a[i - 1] -    ans = max(cnt, ans) +    while cost > k and j >= 0: +        cost -= b[j] +        cnt -= 1 +        j -= 1 +    if cost <= k: +        ans = max(cnt, ans)