program c172

implicit none
integer :: n, m, k, h, i, j, t, x, y, p, q, r, c, d
integer, allocatable :: a(:), b(:)

read *, n, m, k

allocate(a(0:n-1))
allocate(b(0:m-1))

read *, a(:)
read *, b(:)

t = 0
i = 0
j = 0
x = 0
y = 0

do c = 0, n-1
 if (t + a(c) <= k) then
  x = x + 1
 end if
end do
p = c

do d = 0, n-1
 if (t + b(j) <= k) then
  y = y + 1
 end if
end do
q = d

if (p <= q) then
 r = p
else
 r = q
end if

do

x = 0
y = 0

 if (i < n) then
  do h = i, i + r
   x = x + a(h)
  end do
 else
  x = 1145141919
 end if
 
 if (j < m) then
  do h = j, j + r
   y = y + b(h)
  end do
 else
  y = 1145141919
 end if

 if (x <= y .and. t + a(i) <= k .and. i < n) then
  !print *, a(i), i
  t = t + a(i)
  i = i + 1
  r = r - 1
 else if (t + b(j) <= k .and. j < m) then
  !print *, b(j), j
  t = t + b(j)
  j = j + 1
  r = r - 1
 else
  exit
 end if 

end do

print *, i + j

end program c172