from bisect import *



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

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

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



a_b=[0]

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

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



b_b=[0]

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

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



ans=0

for i in range(n+1):

  t_ans=i

  if a_b[i]>k:

    break

  t_ans+=bisect_right(b_b,k-a_b[i])-1

  ans=max(ans,t_ans)



print(ans)
from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

from bisect import bisect_right

from itertools import accumulate



n,m,k=nii()

a=lnii()

b=lnii()

ar=[0]+list(accumulate(a))

br=list(accumulate(b))



ans=0

for i in range(n+1):

  time=ar[i]

  if time>k:

    break

  t_ans=i

  inx=bisect_right(br,k-time)

  t_ans+=inx

  ans=max(ans,t_ans)

print(ans)
from bisect import *

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

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate

n, m, k = nii()
a = lnii()
b = lnii()
ar = [0] + list(accumulate(a))
br = list(accumulate(b))
ans = 0
for i in range(n + 1):
    time = ar[i]
    if time > k:
        break
    t_ans = i
    inx = bisect_right(br, k - time)
    t_ans += inx
    ans = max(ans, t_ans)
print(ans)

-from bisect import * +from sys import stdin -n, m, k = list(map(int, input().split())) -a = list(map(int, input().split())) -b = list(map(int, input().split())) -a_b = [0] -for i in range(1, n + 1): -    a_b.append(a_b[i - 1] + a[i - 1]) -b_b = [0] -for i in range(1, m + 1): -    b_b.append(b_b[i - 1] + b[i - 1]) +nii = lambda: list(map(int, stdin.readline().split())) +lnii = lambda: list(map(int, stdin.readline().split())) +from bisect import bisect_right +from itertools import accumulate + +n, m, k = nii() +a = lnii() +b = lnii() +ar = [0] + list(accumulate(a)) +br = list(accumulate(b)) +    time = ar[i] +    if time > k: +        break -    if a_b[i] > k: -        break -    t_ans += bisect_right(b_b, k - a_b[i]) - 1 +    inx = bisect_right(br, k - time) +    t_ans += inx