import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





def cumsum(a):

    """l[i] = sum(a[:i]) なるlを返す

    sum(a[i:j]) == l[j+1] - l[i]

    """

    c = 0

    l = [None] * (len(a)+1)

    for i,num in enumerate(a):

        l[i] = c

        c += num

    l[-1] = c

    return l



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

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

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



ca = cumsum(a)

cb = cumsum(b)



def sub(x):

    res = float("inf")

    for i in range(x+1):

        if i>n or (x-i)>m:

            continue

        res = min(res, ca[i] + cb[x-i])

    return res<=k

l = 0

r = n+m+1

while l+1<r:

    mm = (l+r)//2

    if sub(mm):

        l = mm

    else:

        r = mm

print(l)
import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





def cumsum(a):

    """l[i] = sum(a[:i]) なるlを返す

    sum(a[i:j]) == l[j+1] - l[i]

    """

    c = 0

    l = [None] * (len(a)+1)

    for i,num in enumerate(a):

        l[i] = c

        c += num

    l[-1] = c

    return l



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

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

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



r = m-1

s = sum(b)

num = m

best = 0

while s>k and r>=0:

    s -= b[r]

    r -= 1

    num -= 1

if s<=k:

    best = max(best, num)

for l in range(n):

    num += 1

    s += a[l]

    while s>k and r>=0:

        s -= b[r]

        r -= 1

        num -= 1

    if s<=k:

        best = max(best, num)

print(best)
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a) + 1)
    for i, num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l


n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = cumsum(a)
cb = cumsum(b)


def sub(x):
    res = float("inf")
    for i in range(x + 1):
        if i > n or (x - i) > m:
            continue
        res = min(res, ca[i] + cb[x - i])
    return res <= k


l = 0
r = n + m + 1
while l + 1 < r:
    mm = (l + r) // 2
    if sub(mm):
        l = mm
    else:
        r = mm
print(l)

import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a) + 1)
    for i, num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l


n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = m - 1
s = sum(b)
num = m
best = 0
while s > k and r >= 0:
    s -= b[r]
    r -= 1
    num -= 1
if s <= k:
    best = max(best, num)
for l in range(n):
    num += 1
    s += a[l]
    while s > k and r >= 0:
        s -= b[r]
        r -= 1
        num -= 1
    if s <= k:
        best = max(best, num)
print(best)

-ca = cumsum(a) -cb = cumsum(b) - - -def sub(x): -    res = float("inf") -    for i in range(x + 1): -        if i > n or (x - i) > m: -            continue -        res = min(res, ca[i] + cb[x - i]) -    return res <= k - - -l = 0 -r = n + m + 1 -while l + 1 < r: -    mm = (l + r) // 2 -    if sub(mm): -        l = mm -    else: -        r = mm -print(l) +r = m - 1 +s = sum(b) +num = m +best = 0 +while s > k and r >= 0: +    s -= b[r] +    r -= 1 +    num -= 1 +if s <= k: +    best = max(best, num) +for l in range(n): +    num += 1 +    s += a[l] +    while s > k and r >= 0: +        s -= b[r] +        r -= 1 +        num -= 1 +    if s <= k: +        best = max(best, num) +print(best)