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

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

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

ans = 0

s = 0

b_count = 0

for i in range(m):

    if s + b[i] <= k:

        s += b[i]

        ans += 1

        b_count = i+1

    else:

        break

a_count = 0

while True:

    if a_count < n and s+a[a_count] <= k:

        s += a[a_count]

        a_count += 1

        ans += 1

    else:

        break

now = ans

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

    s -= b[i]

    now -= 1

    while True:

        if a_count < n and s +a[a_count] <= k:

            s += a[a_count]

            a_count += 1

            now += 1

        else:

            break

    ans = max(now, ans)

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

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

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

sa = [0]

for i in range(n):

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

inf = 1001001001

sb = [-inf, 0]

for i in range(m):

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

sb.append(inf)

ans = 0

for i in range(n+1):

    s = sa[i]

    l = 0

    r = len(sb) - 1

    while l+1 < r:

        m = (l+r) //2

        if s + sb[m] <= k:

            l = m

        else:

            r = m

    if l == 0:

        continue

    else:

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

print(ans)
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
s = 0
b_count = 0
for i in range(m):
    if s + b[i] <= k:
        s += b[i]
        ans += 1
        b_count = i + 1
    else:
        break
a_count = 0
while True:
    if a_count < n and s + a[a_count] <= k:
        s += a[a_count]
        a_count += 1
        ans += 1
    else:
        break
now = ans
for i in range(b_count - 1, -1, -1):
    s -= b[i]
    now -= 1
    while True:
        if a_count < n and s + a[a_count] <= k:
            s += a[a_count]
            a_count += 1
            now += 1
        else:
            break
    ans = max(now, ans)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
for i in range(n):
    sa.append(sa[-1] + a[i])
inf = 1001001001
sb = [-inf, 0]
for i in range(m):
    sb.append(sb[-1] + b[i])
sb.append(inf)
ans = 0
for i in range(n + 1):
    s = sa[i]
    l = 0
    r = len(sb) - 1
    while l + 1 < r:
        m = (l + r) // 2
        if s + sb[m] <= k:
            l = m
        else:
            r = m
    if l == 0:
        continue
    else:
        ans = max(ans, i + l - 1)
print(ans)

+sa = [0] +for i in range(n): +    sa.append(sa[-1] + a[i]) +inf = 1001001001 +sb = [-inf, 0] +for i in range(m): +    sb.append(sb[-1] + b[i]) +sb.append(inf) -s = 0 -b_count = 0 -for i in range(m): -    if s + b[i] <= k: -        s += b[i] -        ans += 1 -        b_count = i + 1 +for i in range(n + 1): +    s = sa[i] +    l = 0 +    r = len(sb) - 1 +    while l + 1 < r: +        m = (l + r) // 2 +        if s + sb[m] <= k: +            l = m +        else: +            r = m +    if l == 0: +        continue -        break -a_count = 0 -while True: -    if a_count < n and s + a[a_count] <= k: -        s += a[a_count] -        a_count += 1 -        ans += 1 -    else: -        break -now = ans -for i in range(b_count - 1, -1, -1): -    s -= b[i] -    now -= 1 -    while True: -        if a_count < n and s + a[a_count] <= k: -            s += a[a_count] -            a_count += 1 -            now += 1 -        else: -            break -    ans = max(now, ans) +        ans = max(ans, i + l - 1)