N, M, K = list(map(int, input().split()))



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

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

A = [0] + A

B = [0] + B

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

  A[i] += A[i-1]

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

  B[i] += B[i-1]

start = 0

end = N+1

while end-start > 1:

  sep = (start+end)//2

  if A[sep] <= K:

    start = sep

  else:

    end = sep

if start==N:

  alim = start

elif A[end]>K:

  alim = start

else:

  alim = end

blim = 0

start = blim

end = M+1

ans = alim

ansalim = -1

ansblim = -1

for _ in range(alim+1):

  Bmax = K-A[alim]

  #print("Bmax" , Bmax)

  while end-start > 1:

    sep = (start+end)//2

    #print(blim,start, end, sep)

    if B[sep] <= Bmax:

      start = sep

    else:

      end = sep

  if start==M:

    blim = start

  elif B[end]>Bmax:

    blim = start

  else:

    blim = end

  

  ans = max(blim + alim, ans)

  start = sep-1

  end = M+1

  alim -= 1

print(ans)
N,M,K=list(map(int,input().split()))

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

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



#入力終わり





#累積和とる



A_wa = [0]

for i in range(N) :

    A_wa.append(A_wa[i]+A[i])



B_wa = [0]

for i in range(M) :

    B_wa.append(B_wa[i]+B[i])



a = N

ans = 0

for b in range(M+1):

  A_lim = K - B_wa[b]

  if A_lim < 0:

    break

  while A_wa[a] > A_lim and a > 0:

    a -= 1

  ans = max(a + b, ans)

print(ans)

  

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
for i in range(1, N + 1):
    A[i] += A[i - 1]
for i in range(1, M + 1):
    B[i] += B[i - 1]
start = 0
end = N + 1
while end - start > 1:
    sep = (start + end) // 2
    if A[sep] <= K:
        start = sep
    else:
        end = sep
if start == N:
    alim = start
elif A[end] > K:
    alim = start
else:
    alim = end
blim = 0
start = blim
end = M + 1
ans = alim
ansalim = -1
ansblim = -1
for _ in range(alim + 1):
    Bmax = K - A[alim]
    # print("Bmax" , Bmax)
    while end - start > 1:
        sep = (start + end) // 2
        # print(blim,start, end, sep)
        if B[sep] <= Bmax:
            start = sep
        else:
            end = sep
    if start == M:
        blim = start
    elif B[end] > Bmax:
        blim = start
    else:
        blim = end
    ans = max(blim + alim, ans)
    start = sep - 1
    end = M + 1
    alim -= 1
print(ans)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 入力終わり
# 累積和とる
A_wa = [0]
for i in range(N):
    A_wa.append(A_wa[i] + A[i])
B_wa = [0]
for i in range(M):
    B_wa.append(B_wa[i] + B[i])
a = N
ans = 0
for b in range(M + 1):
    A_lim = K - B_wa[b]
    if A_lim < 0:
        break
    while A_wa[a] > A_lim and a > 0:
        a -= 1
    ans = max(a + b, ans)
print(ans)

-A = [0] + A -B = [0] + B -for i in range(1, N + 1): -    A[i] += A[i - 1] -for i in range(1, M + 1): -    B[i] += B[i - 1] -start = 0 -end = N + 1 -while end - start > 1: -    sep = (start + end) // 2 -    if A[sep] <= K: -        start = sep -    else: -        end = sep -if start == N: -    alim = start -elif A[end] > K: -    alim = start -else: -    alim = end -blim = 0 -start = blim -end = M + 1 -ans = alim -ansalim = -1 -ansblim = -1 -for _ in range(alim + 1): -    Bmax = K - A[alim] -    # print("Bmax" , Bmax) -    while end - start > 1: -        sep = (start + end) // 2 -        # print(blim,start, end, sep) -        if B[sep] <= Bmax: -            start = sep -        else: -            end = sep -    if start == M: -        blim = start -    elif B[end] > Bmax: -        blim = start -    else: -        blim = end -    ans = max(blim + alim, ans) -    start = sep - 1 -    end = M + 1 -    alim -= 1 +# 入力終わり +# 累積和とる +A_wa = [0] +for i in range(N): +    A_wa.append(A_wa[i] + A[i]) +B_wa = [0] +for i in range(M): +    B_wa.append(B_wa[i] + B[i]) +a = N +ans = 0 +for b in range(M + 1): +    A_lim = K - B_wa[b] +    if A_lim < 0: +        break +    while A_wa[a] > A_lim and a > 0: +        a -= 1 +    ans = max(a + b, ans)