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

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

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

new_a_list = [[0, 0]]

a_sum = 0

for i in range(0, n):

    a_sum += a_list[i]

    if a_sum <= k:

        new_a_list.append([i + 1, a_sum])

    else:

        break



best = len(new_a_list) - 1

b_sum = 0

a_sum = new_a_list[-1][1]

a_count = new_a_list[-1][0]

flag = 1

for i in range(0, m):

    b_sum += b_list[i]

    while True:

        if b_sum <= k - a_sum:

            if best < i + 1 + a_count:

                best = i + 1 + a_count

            break

        if a_count == 0:

            flag = 0

            break

        a_count -= 1

        a_sum = new_a_list[-(len(new_a_list) - a_count)][1]

    if flag == 0:

        break

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

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

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

a, b = [0], [0]

for i in range(N):

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

for i in range(M):

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

ans, j = 0, M

for i in range(N + 1):

  if a[i] > K:

    break

  while b[j] > K - a[i]:

    j -= 1

  ans = max(ans, i + j)

print(ans)
n, m, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
new_a_list = [[0, 0]]
a_sum = 0
for i in range(0, n):
    a_sum += a_list[i]
    if a_sum <= k:
        new_a_list.append([i + 1, a_sum])
    else:
        break
best = len(new_a_list) - 1
b_sum = 0
a_sum = new_a_list[-1][1]
a_count = new_a_list[-1][0]
flag = 1
for i in range(0, m):
    b_sum += b_list[i]
    while True:
        if b_sum <= k - a_sum:
            if best < i + 1 + a_count:
                best = i + 1 + a_count
            break
        if a_count == 0:
            flag = 0
            break
        a_count -= 1
        a_sum = new_a_list[-(len(new_a_list) - a_count)][1]
    if flag == 0:
        break
print(best)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

-n, m, k = list(map(int, input().split())) -a_list = list(map(int, input().split())) -b_list = list(map(int, input().split())) -new_a_list = [[0, 0]] -a_sum = 0 -for i in range(0, n): -    a_sum += a_list[i] -    if a_sum <= k: -        new_a_list.append([i + 1, a_sum]) -    else: +N, M, K = list(map(int, input().split())) +A = list(map(int, input().split())) +B = list(map(int, input().split())) +a, b = [0], [0] +for i in range(N): +    a.append(a[i] + A[i]) +for i in range(M): +    b.append(b[i] + B[i]) +ans, j = 0, M +for i in range(N + 1): +    if a[i] > K: -best = len(new_a_list) - 1 -b_sum = 0 -a_sum = new_a_list[-1][1] -a_count = new_a_list[-1][0] -flag = 1 -for i in range(0, m): -    b_sum += b_list[i] -    while True: -        if b_sum <= k - a_sum: -            if best < i + 1 + a_count: -                best = i + 1 + a_count -            break -        if a_count == 0: -            flag = 0 -            break -        a_count -= 1 -        a_sum = new_a_list[-(len(new_a_list) - a_count)][1] -    if flag == 0: -        break -print(best) +    while b[j] > K - a[i]: +        j -= 1 +    ans = max(ans, i + j) +print(ans)