import bisect

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

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

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

a_sum=[]

b_sum=[]

a_sum.append(0)

b_sum.append(0)

for i in range(n):

    a_sum.append(a_sum[i]+a[i])

for j in range(m):

    b_sum.append(b_sum[j]+b[j])

ans=0

for x in range(n+1):

    timecount=k-a_sum[x]

    if timecount>=0:

        y=bisect.bisect_right(b_sum,k-a_sum[x])-1

        ans=max(x+y,ans)

    else:

        break

print(ans)

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

from itertools import accumulate

from bisect import bisect_right

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

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

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

bc=[0]+list(accumulate(b))

temp=0



for i in range(n+1):

    if ac[i]<=k:

        count=i

        count+=bisect_right(bc,k-ac[i])-1

        temp=max(temp,count)

print(temp)
import bisect

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sum = []
b_sum = []
a_sum.append(0)
b_sum.append(0)
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for j in range(m):
    b_sum.append(b_sum[j] + b[j])
ans = 0
for x in range(n + 1):
    timecount = k - a_sum[x]
    if timecount >= 0:
        y = bisect.bisect_right(b_sum, k - a_sum[x]) - 1
        ans = max(x + y, ans)
    else:
        break
print(ans)

n, m, k = list(map(int, input().split()))
from itertools import accumulate
from bisect import bisect_right

a = list(map(int, input().split()))
b = list(map(int, input().split()))
ac = [0] + list(accumulate(a))
bc = [0] + list(accumulate(b))
temp = 0
for i in range(n + 1):
    if ac[i] <= k:
        count = i
        count += bisect_right(bc, k - ac[i]) - 1
        temp = max(temp, count)
print(temp)

-import bisect +n, m, k = list(map(int, input().split())) +from itertools import accumulate +from bisect import bisect_right -n, m, k = list(map(int, input().split())) -a_sum = [] -b_sum = [] -a_sum.append(0) -b_sum.append(0) -for i in range(n): -    a_sum.append(a_sum[i] + a[i]) -for j in range(m): -    b_sum.append(b_sum[j] + b[j]) -ans = 0 -for x in range(n + 1): -    timecount = k - a_sum[x] -    if timecount >= 0: -        y = bisect.bisect_right(b_sum, k - a_sum[x]) - 1 -        ans = max(x + y, ans) -    else: -        break -print(ans) +ac = [0] + list(accumulate(a)) +bc = [0] + list(accumulate(b)) +temp = 0 +for i in range(n + 1): +    if ac[i] <= k: +        count = i +        count += bisect_right(bc, k - ac[i]) - 1 +        temp = max(temp, count) +print(temp)