import bisect

# listのpopを使う

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

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

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

# 純粋に小さい方を読んでいく

ans = 0

# 1番上しか読めない

# while K >= A[0] or K >= B[0]:

#     if A[0]

cumulative_sum_of_A = [0]

cumulative_sum_of_B = [0]

for i in range(N):

    cumulative_sum_of_A.append(cumulative_sum_of_A[-1]+A[i])



for i in range(M):

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



# print(cumulative_sum_of_A)

# print(cumulative_sum_of_B)



ans = 0

for i in range(N+1):

    # print(ans)

    if cumulative_sum_of_A[i] > K:  # それ以上Aを読めないならアウト

        break

    tmp = i  # A側の本をi冊読む  # 0の場合もあり

    remaining = K - cumulative_sum_of_A[i]  # 残り時間

    upper_bound = bisect.bisect_right(cumulative_sum_of_B, remaining)-1

    tmp += upper_bound

    ans = max(tmp, ans)

print(ans)

from bisect import bisect_left, bisect_right

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

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

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



ruisekiwa_of_A = [0]

ruisekiwa_of_B = [0]

for a in A:

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

for b in B:

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

# ansの最大値をとる

ans = 0

for i in range(N+1):

    tmp = 0

    if K >= ruisekiwa_of_A[i]:

        tmp = i

    else:

        continue

    tmp += bisect_right(ruisekiwa_of_B, K-ruisekiwa_of_A[i])-1

    ans = max(ans, tmp)

print(ans)

import bisect

# listのpopを使う
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 純粋に小さい方を読んでいく
ans = 0
# 1番上しか読めない
# while K >= A[0] or K >= B[0]:
#     if A[0]
cumulative_sum_of_A = [0]
cumulative_sum_of_B = [0]
for i in range(N):
    cumulative_sum_of_A.append(cumulative_sum_of_A[-1] + A[i])
for i in range(M):
    cumulative_sum_of_B.append(cumulative_sum_of_B[-1] + B[i])
# print(cumulative_sum_of_A)
# print(cumulative_sum_of_B)
ans = 0
for i in range(N + 1):
    # print(ans)
    if cumulative_sum_of_A[i] > K:  # それ以上Aを読めないならアウト
        break
    tmp = i  # A側の本をi冊読む  # 0の場合もあり
    remaining = K - cumulative_sum_of_A[i]  # 残り時間
    upper_bound = bisect.bisect_right(cumulative_sum_of_B, remaining) - 1
    tmp += upper_bound
    ans = max(tmp, ans)
print(ans)

from bisect import bisect_left, bisect_right

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ruisekiwa_of_A = [0]
ruisekiwa_of_B = [0]
for a in A:
    ruisekiwa_of_A.append(ruisekiwa_of_A[-1] + a)
for b in B:
    ruisekiwa_of_B.append(ruisekiwa_of_B[-1] + b)
# ansの最大値をとる
ans = 0
for i in range(N + 1):
    tmp = 0
    if K >= ruisekiwa_of_A[i]:
        tmp = i
    else:
        continue
    tmp += bisect_right(ruisekiwa_of_B, K - ruisekiwa_of_A[i]) - 1
    ans = max(ans, tmp)
print(ans)

-import bisect +from bisect import bisect_left, bisect_right -# listのpopを使う -# 純粋に小さい方を読んでいく -ans = 0 -# 1番上しか読めない -# while K >= A[0] or K >= B[0]: -#     if A[0] -cumulative_sum_of_A = [0] -cumulative_sum_of_B = [0] -for i in range(N): -    cumulative_sum_of_A.append(cumulative_sum_of_A[-1] + A[i]) -for i in range(M): -    cumulative_sum_of_B.append(cumulative_sum_of_B[-1] + B[i]) -# print(cumulative_sum_of_A) -# print(cumulative_sum_of_B) +ruisekiwa_of_A = [0] +ruisekiwa_of_B = [0] +for a in A: +    ruisekiwa_of_A.append(ruisekiwa_of_A[-1] + a) +for b in B: +    ruisekiwa_of_B.append(ruisekiwa_of_B[-1] + b) +# ansの最大値をとる -    # print(ans) -    if cumulative_sum_of_A[i] > K:  # それ以上Aを読めないならアウト -        break -    tmp = i  # A側の本をi冊読む  # 0の場合もあり -    remaining = K - cumulative_sum_of_A[i]  # 残り時間 -    upper_bound = bisect.bisect_right(cumulative_sum_of_B, remaining) - 1 -    tmp += upper_bound -    ans = max(tmp, ans) +    tmp = 0 +    if K >= ruisekiwa_of_A[i]: +        tmp = i +    else: +        continue +    tmp += bisect_right(ruisekiwa_of_B, K - ruisekiwa_of_A[i]) - 1 +    ans = max(ans, tmp)