import bisect

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

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

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



sum_alist=[0]

for i in range(N):

  sum_alist.append(sum_alist[-1]+alist[i])

#print(sum_alist)



sum_blist=[0]

for i in range(M):

  sum_blist.append(sum_blist[-1]+blist[i])

#print(sum_blist)



limit_a=bisect.bisect(sum_alist,K)

#print(limit_a)



limit_b=bisect.bisect(sum_blist,K)

#print(limit_b)



answer=0

for i in reversed(list(range(1,limit_a))):

  a_sum=sum_alist[i]

  b_sum=K-a_sum

  pos_b=bisect.bisect(sum_blist,b_sum)

  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)

  answer=max(answer,i+pos_b-1)



for i in reversed(list(range(1,limit_b))):

  b_sum=sum_blist[i]

  a_sum=K-b_sum

  pos_a=bisect.bisect(sum_alist,a_sum)

  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)

  answer=max(answer,i+pos_a-1)

  

if limit_a==1:

  pos_b=bisect.bisect(sum_blist,K)

  answer=pos_b-1

elif limit_b==1:

  pos_a=bisect.bisect(sum_alist,K)

  answer=pos_a-1

  

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

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

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



sum_alist=[0]

for a in alist:

  sum_alist.append(sum_alist[-1]+a)

sum_blist=[0]

for b in blist:

  sum_blist.append(sum_blist[-1]+b)

  

index_b=M

answer=0

for i in range(N+1):

  sum_a=sum_alist[i]

  if sum_a>K:

    break

    

  while sum_a+sum_blist[index_b]>K:

    index_b-=1

    

  #print(i,index_b)

  answer=max(answer,i+index_b)

  

print(answer)
import bisect

N, M, K = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
sum_alist = [0]
for i in range(N):
    sum_alist.append(sum_alist[-1] + alist[i])
# print(sum_alist)
sum_blist = [0]
for i in range(M):
    sum_blist.append(sum_blist[-1] + blist[i])
# print(sum_blist)
limit_a = bisect.bisect(sum_alist, K)
# print(limit_a)
limit_b = bisect.bisect(sum_blist, K)
# print(limit_b)
answer = 0
for i in reversed(list(range(1, limit_a))):
    a_sum = sum_alist[i]
    b_sum = K - a_sum
    pos_b = bisect.bisect(sum_blist, b_sum)
    # print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
    answer = max(answer, i + pos_b - 1)
for i in reversed(list(range(1, limit_b))):
    b_sum = sum_blist[i]
    a_sum = K - b_sum
    pos_a = bisect.bisect(sum_alist, a_sum)
    # print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
    answer = max(answer, i + pos_a - 1)
if limit_a == 1:
    pos_b = bisect.bisect(sum_blist, K)
    answer = pos_b - 1
elif limit_b == 1:
    pos_a = bisect.bisect(sum_alist, K)
    answer = pos_a - 1
print(answer)

N, M, K = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
sum_alist = [0]
for a in alist:
    sum_alist.append(sum_alist[-1] + a)
sum_blist = [0]
for b in blist:
    sum_blist.append(sum_blist[-1] + b)
index_b = M
answer = 0
for i in range(N + 1):
    sum_a = sum_alist[i]
    if sum_a > K:
        break
    while sum_a + sum_blist[index_b] > K:
        index_b -= 1
    # print(i,index_b)
    answer = max(answer, i + index_b)
print(answer)

-import bisect - -for i in range(N): -    sum_alist.append(sum_alist[-1] + alist[i]) -# print(sum_alist) +for a in alist: +    sum_alist.append(sum_alist[-1] + a) -for i in range(M): -    sum_blist.append(sum_blist[-1] + blist[i]) -# print(sum_blist) -limit_a = bisect.bisect(sum_alist, K) -# print(limit_a) -limit_b = bisect.bisect(sum_blist, K) -# print(limit_b) +for b in blist: +    sum_blist.append(sum_blist[-1] + b) +index_b = M -for i in reversed(list(range(1, limit_a))): -    a_sum = sum_alist[i] -    b_sum = K - a_sum -    pos_b = bisect.bisect(sum_blist, b_sum) -    # print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum) -    answer = max(answer, i + pos_b - 1) -for i in reversed(list(range(1, limit_b))): -    b_sum = sum_blist[i] -    a_sum = K - b_sum -    pos_a = bisect.bisect(sum_alist, a_sum) -    # print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum) -    answer = max(answer, i + pos_a - 1) -if limit_a == 1: -    pos_b = bisect.bisect(sum_blist, K) -    answer = pos_b - 1 -elif limit_b == 1: -    pos_a = bisect.bisect(sum_alist, K) -    answer = pos_a - 1 +for i in range(N + 1): +    sum_a = sum_alist[i] +    if sum_a > K: +        break +    while sum_a + sum_blist[index_b] > K: +        index_b -= 1 +    # print(i,index_b) +    answer = max(answer, i + index_b)