import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import accumulate, permutations, combinations, product

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7



N, M , W = MAP()

A = LIST()

B = LIST()



sa = sum(A)

sb = sum(B)

A.reverse()

C = A + B

# print(C)

ans = 0

left_wa = 0

right_wa = 0





ruiseki = C.copy()

ruiseki = [0] + ruiseki

for i in range(len(ruiseki)-1):

    ruiseki[i+1] = ruiseki[i] + ruiseki[i+1]

# print(ruiseki)

left = 0

# for right in range(1, len(C)+1):

#     ruiseki[left:right]

idx = 0

wa = 0

ans = 0

# print(len(ruiseki))

for right in range(len(A), len(ruiseki)):

    # idx += 1

    # print("right:", right)

    wa = ruiseki[right] - ruiseki[left]

    # if

    while wa > W:

        left += 1

        wa = ruiseki[right] - ruiseki[left]

    if left <= len(A):

        tmp = right - left

        # print(tmp)

        ans = max(tmp, ans)

    else:

        break

    # print("left, right, :", left, right)



print(ans)



from bisect import bisect_right





def main():

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

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

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



    CUSUM_A = [0] * (N+1)

    CUSUM_B = [0] * (M+1)



    for i, a in enumerate(A):

        CUSUM_A[i+1] = CUSUM_A[i] + a



    for i, b in enumerate(B):

        CUSUM_B[i+1] = CUSUM_B[i] + b





    # Aの本をi冊, Bの本をj冊読む i:[0:N],j:[0,M]

    ans = 0

    j = M

    for i in range(N+1):

        # Aの本だけでK超えてたらBをいくら減らしてもだめ ここで場合分けしておくことでj>=0を保証できる (j=0のとき確実に読めるので)

        if CUSUM_A[i] > K:

            break



        SUM_VAL = CUSUM_A[i] + CUSUM_B[j]

        

        while SUM_VAL > K:

            j -= 1

            SUM_VAL = CUSUM_A[i] + CUSUM_B[j]

        

        ans = max(ans, i+j)

        

    print(ans)



if __name__ == "__main__":

    main()
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, M, W = MAP()
A = LIST()
B = LIST()
sa = sum(A)
sb = sum(B)
A.reverse()
C = A + B
# print(C)
ans = 0
left_wa = 0
right_wa = 0
ruiseki = C.copy()
ruiseki = [0] + ruiseki
for i in range(len(ruiseki) - 1):
    ruiseki[i + 1] = ruiseki[i] + ruiseki[i + 1]
# print(ruiseki)
left = 0
# for right in range(1, len(C)+1):
#     ruiseki[left:right]
idx = 0
wa = 0
ans = 0
# print(len(ruiseki))
for right in range(len(A), len(ruiseki)):
    # idx += 1
    # print("right:", right)
    wa = ruiseki[right] - ruiseki[left]
    # if
    while wa > W:
        left += 1
        wa = ruiseki[right] - ruiseki[left]
    if left <= len(A):
        tmp = right - left
        # print(tmp)
        ans = max(tmp, ans)
    else:
        break
    # print("left, right, :", left, right)
print(ans)

from bisect import bisect_right


def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    CUSUM_A = [0] * (N + 1)
    CUSUM_B = [0] * (M + 1)
    for i, a in enumerate(A):
        CUSUM_A[i + 1] = CUSUM_A[i] + a
    for i, b in enumerate(B):
        CUSUM_B[i + 1] = CUSUM_B[i] + b
    # Aの本をi冊, Bの本をj冊読む i:[0:N],j:[0,M]
    ans = 0
    j = M
    for i in range(N + 1):
        # Aの本だけでK超えてたらBをいくら減らしてもだめ ここで場合分けしておくことでj>=0を保証できる (j=0のとき確実に読めるので)
        if CUSUM_A[i] > K:
            break
        SUM_VAL = CUSUM_A[i] + CUSUM_B[j]
        while SUM_VAL > K:
            j -= 1
            SUM_VAL = CUSUM_A[i] + CUSUM_B[j]
        ans = max(ans, i + j)
    print(ans)


if __name__ == "__main__":
    main()

-import sys, re -from collections import deque, defaultdict, Counter -from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians -from itertools import accumulate, permutations, combinations, product -from operator import itemgetter, mul -from copy import deepcopy -from string import ascii_lowercase, ascii_uppercase, digits -from bisect import bisect, bisect_left -from fractions import gcd -from heapq import heappush, heappop -from functools import reduce +from bisect import bisect_right -def input(): -    return sys.stdin.readline().strip() +def main(): +    N, M, K = list(map(int, input().split())) +    A = list(map(int, input().split())) +    B = list(map(int, input().split())) +    CUSUM_A = [0] * (N + 1) +    CUSUM_B = [0] * (M + 1) +    for i, a in enumerate(A): +        CUSUM_A[i + 1] = CUSUM_A[i] + a +    for i, b in enumerate(B): +        CUSUM_B[i + 1] = CUSUM_B[i] + b +    # Aの本をi冊, Bの本をj冊読む i:[0:N],j:[0,M] +    ans = 0 +    j = M +    for i in range(N + 1): +        # Aの本だけでK超えてたらBをいくら減らしてもだめ ここで場合分けしておくことでj>=0を保証できる (j=0のとき確実に読めるので) +        if CUSUM_A[i] > K: +            break +        SUM_VAL = CUSUM_A[i] + CUSUM_B[j] +        while SUM_VAL > K: +            j -= 1 +            SUM_VAL = CUSUM_A[i] + CUSUM_B[j] +        ans = max(ans, i + j) +    print(ans) -def INT(): -    return int(eval(input())) - - -def MAP(): -    return list(map(int, input().split())) - - -def LIST(): -    return list(map(int, input().split())) - - -def ZIP(n): -    return list(zip(*(MAP() for _ in range(n)))) - - -sys.setrecursionlimit(10**9) -INF = float("inf") -mod = 10**9 + 7 -N, M, W = MAP() -A = LIST() -B = LIST() -sa = sum(A) -sb = sum(B) -A.reverse() -C = A + B -# print(C) -ans = 0 -left_wa = 0 -right_wa = 0 -ruiseki = C.copy() -ruiseki = [0] + ruiseki -for i in range(len(ruiseki) - 1): -    ruiseki[i + 1] = ruiseki[i] + ruiseki[i + 1] -# print(ruiseki) -left = 0 -# for right in range(1, len(C)+1): -#     ruiseki[left:right] -idx = 0 -wa = 0 -ans = 0 -# print(len(ruiseki)) -for right in range(len(A), len(ruiseki)): -    # idx += 1 -    # print("right:", right) -    wa = ruiseki[right] - ruiseki[left] -    # if -    while wa > W: -        left += 1 -        wa = ruiseki[right] - ruiseki[left] -    if left <= len(A): -        tmp = right - left -        # print(tmp) -        ans = max(tmp, ans) -    else: -        break -    # print("left, right, :", left, right) -print(ans) +if __name__ == "__main__": +    main()