from bisect import *

def solve():

    ans = 0

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

    A = list(map(int, input().split()))+[float('inf')]

    B = list(map(int, input().split()))+[float('inf')]

    cumA = [0]*(N+1)

    cumB = [0]*(M+1)

    for i in range(N):

        cumA[i+1] = cumA[i]+A[i]

    for i in range(M):

        cumB[i+1] = cumB[i]+B[i]

    for i in range(N+1):

        rest = K-cumA[i]

        if rest<0:

            break

        ind = bisect_right(cumB,rest)

        ans = max(ans,i+ind-1)

    return ans

print((solve()))
from itertools import groupby, accumulate, product, permutations, combinations

def solve():

    ans = 0

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

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

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

    A = [0]+list(accumulate(A))

    B = [0]+list(accumulate(B))

    b = M

    for a in range(N+1):

        if A[a]>K:

            break

        while A[a]+B[b]>K:

            b -= 1

        ans = max(a+b,ans)

    return ans

print((solve()))
from bisect import *


def solve():
    ans = 0
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split())) + [float("inf")]
    B = list(map(int, input().split())) + [float("inf")]
    cumA = [0] * (N + 1)
    cumB = [0] * (M + 1)
    for i in range(N):
        cumA[i + 1] = cumA[i] + A[i]
    for i in range(M):
        cumB[i + 1] = cumB[i] + B[i]
    for i in range(N + 1):
        rest = K - cumA[i]
        if rest < 0:
            break
        ind = bisect_right(cumB, rest)
        ans = max(ans, i + ind - 1)
    return ans


print((solve()))

from itertools import groupby, accumulate, product, permutations, combinations


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


print((solve()))

-from bisect import * +from itertools import groupby, accumulate, product, permutations, combinations -    A = list(map(int, input().split())) + [float("inf")] -    B = list(map(int, input().split())) + [float("inf")] -    cumA = [0] * (N + 1) -    cumB = [0] * (M + 1) -    for i in range(N): -        cumA[i + 1] = cumA[i] + A[i] -    for i in range(M): -        cumB[i + 1] = cumB[i] + B[i] -    for i in range(N + 1): -        rest = K - cumA[i] -        if rest < 0: +    A = list(map(int, input().split())) +    B = list(map(int, input().split())) +    A = [0] + list(accumulate(A)) +    B = [0] + list(accumulate(B)) +    b = M +    for a in range(N + 1): +        if A[a] > K: -        ind = bisect_right(cumB, rest) -        ans = max(ans, i + ind - 1) +        while A[a] + B[b] > K: +            b -= 1 +        ans = max(a + b, ans)