def ii():return int(eval(input()))

def iim():return list(map(int,input().split()))

def iil():return list(map(int,input().split()))



import numpy as np



def binarySearch(lis,key):

    ng = -1

    ok = len(lis)

    while abs(ok-ng) > 1:

        mid = (ok+ng)//2

        if isOk(lis,mid,key): ok = mid

        else: ng = mid

    return ok



def isOk(lis,index,key):

    if lis[index] > key: return True

    else: return False



n,m,k = iim()

a = iil()

cuma = np.cumsum(a)

b = iil()

cumb = np.cumsum(b)



ans = binarySearch(cumb,k)

for i,item in enumerate(cuma):

    if item > k:

        break



    res = k-item

    plus = binarySearch(cumb,res)

    ans = max(ans,i+1+plus)



print(ans)

def ii():return int(eval(input()))

def iim():return list(map(int,input().split()))

def iil():return list(map(int,input().split()))



import numpy as np



n,m,k = iim()

a = iil()

cuma = [0]

for i in a:

    cuma.append(cuma[-1]+i)

b = iil()

cumb = [0]

for i in b:

    cumb.append(cumb[-1]+i)



best = m

ans = 0

for i in range(n+1):

    if cuma[i] > k:

        break

    while cumb[best] > k-cuma[i]:

        best -= 1

    ans = max(ans,best+i)



print(ans)

def ii():
    return int(eval(input()))


def iim():
    return list(map(int, input().split()))


def iil():
    return list(map(int, input().split()))


import numpy as np


def binarySearch(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOk(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok


def isOk(lis, index, key):
    if lis[index] > key:
        return True
    else:
        return False


n, m, k = iim()
a = iil()
cuma = np.cumsum(a)
b = iil()
cumb = np.cumsum(b)
ans = binarySearch(cumb, k)
for i, item in enumerate(cuma):
    if item > k:
        break
    res = k - item
    plus = binarySearch(cumb, res)
    ans = max(ans, i + 1 + plus)
print(ans)

def ii():
    return int(eval(input()))


def iim():
    return list(map(int, input().split()))


def iil():
    return list(map(int, input().split()))


import numpy as np

n, m, k = iim()
a = iil()
cuma = [0]
for i in a:
    cuma.append(cuma[-1] + i)
b = iil()
cumb = [0]
for i in b:
    cumb.append(cumb[-1] + i)
best = m
ans = 0
for i in range(n + 1):
    if cuma[i] > k:
        break
    while cumb[best] > k - cuma[i]:
        best -= 1
    ans = max(ans, best + i)
print(ans)

- -def binarySearch(lis, key): -    ng = -1 -    ok = len(lis) -    while abs(ok - ng) > 1: -        mid = (ok + ng) // 2 -        if isOk(lis, mid, key): -            ok = mid -        else: -            ng = mid -    return ok - - -def isOk(lis, index, key): -    if lis[index] > key: -        return True -    else: -        return False - - -cuma = np.cumsum(a) +cuma = [0] +for i in a: +    cuma.append(cuma[-1] + i) -cumb = np.cumsum(b) -ans = binarySearch(cumb, k) -for i, item in enumerate(cuma): -    if item > k: +cumb = [0] +for i in b: +    cumb.append(cumb[-1] + i) +best = m +ans = 0 +for i in range(n + 1): +    if cuma[i] > k: -    res = k - item -    plus = binarySearch(cumb, res) -    ans = max(ans, i + 1 + plus) +    while cumb[best] > k - cuma[i]: +        best -= 1 +    ans = max(ans, best + i)