N,M,K=[int(s) for s in input().split()]

A=[int(s) for s in input().split()]

B=[int(s) for s in input().split()]

Asum=[0 for i in range(N+1)]

Bsum=[0 for i in range(M+1)]

for i in range(N):

  Asum[i+1]=Asum[i]+A[i]

for i in range(M):

  Bsum[i+1]=Bsum[i]+B[i]



def nibu(x):

  time=set()

  for i in range(0,N+1):

    if i>x:

      break

    if x-i>M:

      continue

    time.add(Asum[i]+Bsum[x-i])

  if min(time)<=K:

    return True

  else:

    return False

  

nibu_l=0

nibu_r=N+M

while nibu_r-nibu_l>1:

  c=(nibu_l+nibu_r)//2

  if nibu(c)==True:

    nibu_l=c

  else:

    nibu_r=c

if nibu(nibu_r)==True:

  print(nibu_r)

else:

  print(nibu_l)
import bisect

N,M,K=[int(s) for s in input().split()]

A=[int(s) for s in input().split()]

B=[int(s) for s in input().split()]

Asum=[0 for i in range(N+1)]

Bsum=[0 for i in range(M+1)]

for i in range(N):

  Asum[i+1]=Asum[i]+A[i]

for i in range(M):

  Bsum[i+1]=Bsum[i]+B[i]

ans=[0 for i in range(N+1)]

t=bisect.bisect_right(Bsum,K)-1

ans[0]=t

for i in range(1,N+1):

  if Asum[i]>K:

    break

  while Bsum[t]+Asum[i]>K:

    t-=1

  ans[i]=i+t

print((max(ans)))

  



N, M, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
Asum = [0 for i in range(N + 1)]
Bsum = [0 for i in range(M + 1)]
for i in range(N):
    Asum[i + 1] = Asum[i] + A[i]
for i in range(M):
    Bsum[i + 1] = Bsum[i] + B[i]


def nibu(x):
    time = set()
    for i in range(0, N + 1):
        if i > x:
            break
        if x - i > M:
            continue
        time.add(Asum[i] + Bsum[x - i])
    if min(time) <= K:
        return True
    else:
        return False


nibu_l = 0
nibu_r = N + M
while nibu_r - nibu_l > 1:
    c = (nibu_l + nibu_r) // 2
    if nibu(c) == True:
        nibu_l = c
    else:
        nibu_r = c
if nibu(nibu_r) == True:
    print(nibu_r)
else:
    print(nibu_l)

import bisect

N, M, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
Asum = [0 for i in range(N + 1)]
Bsum = [0 for i in range(M + 1)]
for i in range(N):
    Asum[i + 1] = Asum[i] + A[i]
for i in range(M):
    Bsum[i + 1] = Bsum[i] + B[i]
ans = [0 for i in range(N + 1)]
t = bisect.bisect_right(Bsum, K) - 1
ans[0] = t
for i in range(1, N + 1):
    if Asum[i] > K:
        break
    while Bsum[t] + Asum[i] > K:
        t -= 1
    ans[i] = i + t
print((max(ans)))

+import bisect + - - -def nibu(x): -    time = set() -    for i in range(0, N + 1): -        if i > x: -            break -        if x - i > M: -            continue -        time.add(Asum[i] + Bsum[x - i]) -    if min(time) <= K: -        return True -    else: -        return False - - -nibu_l = 0 -nibu_r = N + M -while nibu_r - nibu_l > 1: -    c = (nibu_l + nibu_r) // 2 -    if nibu(c) == True: -        nibu_l = c -    else: -        nibu_r = c -if nibu(nibu_r) == True: -    print(nibu_r) -else: -    print(nibu_l) +ans = [0 for i in range(N + 1)] +t = bisect.bisect_right(Bsum, K) - 1 +ans[0] = t +for i in range(1, N + 1): +    if Asum[i] > K: +        break +    while Bsum[t] + Asum[i] > K: +        t -= 1 +    ans[i] = i + t +print((max(ans)))