import bisect

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

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

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

sa = [0]

sb = [0]

for i in range(n):

    sa.append(sa[-1] + a[i])

for i in range(m):

    sb.append(sb[-1] + b[i])

ans = 0

for i in range(n+1):

    if sa[i] > k:

        continue

    else:

        j = bisect.bisect_right(sb, k-sa[i])

        ans = max(ans, i+j-1)

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

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

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

sa = [0]

sb = [0]

for i in range(n):

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

for i in range(m):

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

ans = 0

j = m

for i in range(n+1):

    if sa[i] > k:

        break

    while sa[i] + sb[j] > k:

        j -= 1

    ans = max(ans, i + j)

print(ans)
import bisect

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
sb = [0]
for i in range(n):
    sa.append(sa[-1] + a[i])
for i in range(m):
    sb.append(sb[-1] + b[i])
ans = 0
for i in range(n + 1):
    if sa[i] > k:
        continue
    else:
        j = bisect.bisect_right(sb, k - sa[i])
        ans = max(ans, i + j - 1)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
sb = [0]
for i in range(n):
    sa.append(sa[i] + a[i])
for i in range(m):
    sb.append(sb[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
    if sa[i] > k:
        break
    while sa[i] + sb[j] > k:
        j -= 1
    ans = max(ans, i + j)
print(ans)

-import bisect - -    sa.append(sa[-1] + a[i]) +    sa.append(sa[i] + a[i]) -    sb.append(sb[-1] + b[i]) +    sb.append(sb[i] + b[i]) +j = m -        continue -    else: -        j = bisect.bisect_right(sb, k - sa[i]) -        ans = max(ans, i + j - 1) +        break +    while sa[i] + sb[j] > k: +        j -= 1 +    ans = max(ans, i + j)