import bisect

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

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

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

ans = 0

A_cumulative_sum = [0]

B_cumulative_sum = [B[0]]

for i in range(N):

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

for i in range(1, M):

    B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1])



for i in range(N + 1):

    if K < A_cumulative_sum[i]:

        remaining_time = K

        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)

        ans = max(ans, idx)

        break

    else:

        remaining_time = K - A_cumulative_sum[i]

        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)

        ans = max(ans, i + idx)

print(ans)



# 113897


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

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

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

'''

with open('./b09.txt') as f:

    N, M, K = map(int, f.readline().split())

    A = list(map(int, f.readline().split()))

    B = list(map(int, f.readline().split()))

'''

A_cnt = 0

B_cnt = 0

ans = 0

nowK = K

for A_idx in range(N):

    if nowK < A[A_idx]:

        break

    ans += 1

    nowK -= A[A_idx]

    A_cnt += 1

for B_idx in range(M):

    if nowK < B[B_idx]:

        break

    ans += 1

    nowK -= B[B_idx]

    B_cnt += 1

tmp_ans = ans

finish = False

for i in range(A_cnt, 0, -1):

    nowK += A[i - 1]

    tmp_ans -= 1

    for j in range(B_cnt, M):

        if finish or nowK < B[j]:

            break

        nowK -= B[j]

        tmp_ans += 1

        B_cnt += 1

    ans = max(tmp_ans, ans)

print(ans)





import bisect

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
A_cumulative_sum = [0]
B_cumulative_sum = [B[0]]
for i in range(N):
    A_cumulative_sum.append(A[i] + A_cumulative_sum[i])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1])
for i in range(N + 1):
    if K < A_cumulative_sum[i]:
        remaining_time = K
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, idx)
        break
    else:
        remaining_time = K - A_cumulative_sum[i]
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, i + idx)
print(ans)
# 113897

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
"""
with open('./b09.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
"""
A_cnt = 0
B_cnt = 0
ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
    A_cnt += 1
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
    B_cnt += 1
tmp_ans = ans
finish = False
for i in range(A_cnt, 0, -1):
    nowK += A[i - 1]
    tmp_ans -= 1
    for j in range(B_cnt, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        B_cnt += 1
    ans = max(tmp_ans, ans)
print(ans)

-import bisect - +""" +with open('./b09.txt') as f: +    N, M, K = map(int, f.readline().split()) +    A = list(map(int, f.readline().split())) +    B = list(map(int, f.readline().split())) +""" +A_cnt = 0 +B_cnt = 0 -A_cumulative_sum = [0] -B_cumulative_sum = [B[0]] -for i in range(N): -    A_cumulative_sum.append(A[i] + A_cumulative_sum[i]) -for i in range(1, M): -    B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1]) -for i in range(N + 1): -    if K < A_cumulative_sum[i]: -        remaining_time = K -        idx = bisect.bisect_right(B_cumulative_sum, remaining_time) -        ans = max(ans, idx) +nowK = K +for A_idx in range(N): +    if nowK < A[A_idx]: -    else: -        remaining_time = K - A_cumulative_sum[i] -        idx = bisect.bisect_right(B_cumulative_sum, remaining_time) -        ans = max(ans, i + idx) +    ans += 1 +    nowK -= A[A_idx] +    A_cnt += 1 +for B_idx in range(M): +    if nowK < B[B_idx]: +        break +    ans += 1 +    nowK -= B[B_idx] +    B_cnt += 1 +tmp_ans = ans +finish = False +for i in range(A_cnt, 0, -1): +    nowK += A[i - 1] +    tmp_ans -= 1 +    for j in range(B_cnt, M): +        if finish or nowK < B[j]: +            break +        nowK -= B[j] +        tmp_ans += 1 +        B_cnt += 1 +    ans = max(tmp_ans, ans) -# 113897