import sys

sys.setrecursionlimit(10 ** 9)

# input = sys.stdin.readline    ####

def int1(x): return int(x) - 1

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

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

def MI1(): return list(map(int1, input().split()))

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

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def MS(): return input().split()

def LS(): return list(eval(input()))

def LLS(rows_number): return [LS() for _ in range(rows_number)]

def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))

INF = float('inf')

# from math import ceil, floor, log2

# from collections import deque

from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations

# from heapq import heapify, heappop, heappush

# import numpy as np

# from numpy import cumsum  # accumulate

from bisect import bisect_right, bisect_left



def solve():

    N, M, K = MI()

    A = LI()

    B = LI()

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

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



    def is_ok(arg, a):

        # b <= K - a

        # print(arg, B[arg], a, K, B[arg] <= K - a)

        return B[arg] <= K - a



    def meguru_bisect(ng, ok, a):

        while (abs(ok - ng) > 1):

            mid = (ok + ng) // 2

            if is_ok(mid, a):

                ok = mid

            else:

                ng = mid

            # print(ok, ng)

        return ok



    # print(A)

    # print(B)

    ans = 0

    for i, a in enumerate(A):

        idx = meguru_bisect(M+1, -1, a)

        if 0 <= idx <= M:

            ans = max(ans, i + idx)

    print(ans)



        







if __name__ == '__main__':

    solve()

import sys

sys.setrecursionlimit(10 ** 9)

# input = sys.stdin.readline    ####

def int1(x): return int(x) - 1

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

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

def MI1(): return list(map(int1, input().split()))

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

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def MS(): return input().split()

def LS(): return list(eval(input()))

def LLS(rows_number): return [LS() for _ in range(rows_number)]

def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))

INF = float('inf')

# from math import ceil, floor, log2

# from collections import deque

from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations

# from heapq import heapify, heappop, heappush

# import numpy as np

# from numpy import cumsum  # accumulate

from bisect import bisect_right, bisect_left



def solve():

    N, M, K = MI()

    A = LI()

    B = LI()

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

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



    ans = 0

    for i, a in enumerate(A):

        if a > K:

            break

        idx = bisect_right(B, K - a) - 1

        ans = max(ans, i + idx)

    print(ans)



        







if __name__ == '__main__':

    solve()

import sys

sys.setrecursionlimit(10**9)
# input = sys.stdin.readline    ####
def int1(x):
    return int(x) - 1


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


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


def MI1():
    return list(map(int1, input().split()))


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


def LI1():
    return list(map(int1, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def MS():
    return input().split()


def LS():
    return list(eval(input()))


def LLS(rows_number):
    return [LS() for _ in range(rows_number)]


def printlist(lst, k=" "):
    print((k.join(list(map(str, lst)))))


INF = float("inf")
# from math import ceil, floor, log2
# from collections import deque
from itertools import (
    combinations as comb,
    combinations_with_replacement as comb_w,
    accumulate,
    product,
    permutations,
)

# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from bisect import bisect_right, bisect_left


def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))

    def is_ok(arg, a):
        # b <= K - a
        # print(arg, B[arg], a, K, B[arg] <= K - a)
        return B[arg] <= K - a

    def meguru_bisect(ng, ok, a):
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid, a):
                ok = mid
            else:
                ng = mid
            # print(ok, ng)
        return ok

    # print(A)
    # print(B)
    ans = 0
    for i, a in enumerate(A):
        idx = meguru_bisect(M + 1, -1, a)
        if 0 <= idx <= M:
            ans = max(ans, i + idx)
    print(ans)


if __name__ == "__main__":
    solve()

import sys

sys.setrecursionlimit(10**9)
# input = sys.stdin.readline    ####
def int1(x):
    return int(x) - 1


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


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


def MI1():
    return list(map(int1, input().split()))


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


def LI1():
    return list(map(int1, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def MS():
    return input().split()


def LS():
    return list(eval(input()))


def LLS(rows_number):
    return [LS() for _ in range(rows_number)]


def printlist(lst, k=" "):
    print((k.join(list(map(str, lst)))))


INF = float("inf")
# from math import ceil, floor, log2
# from collections import deque
from itertools import (
    combinations as comb,
    combinations_with_replacement as comb_w,
    accumulate,
    product,
    permutations,
)

# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from bisect import bisect_right, bisect_left


def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))
    ans = 0
    for i, a in enumerate(A):
        if a > K:
            break
        idx = bisect_right(B, K - a) - 1
        ans = max(ans, i + idx)
    print(ans)


if __name__ == "__main__":
    solve()

- -    def is_ok(arg, a): -        # b <= K - a -        # print(arg, B[arg], a, K, B[arg] <= K - a) -        return B[arg] <= K - a - -    def meguru_bisect(ng, ok, a): -        while abs(ok - ng) > 1: -            mid = (ok + ng) // 2 -            if is_ok(mid, a): -                ok = mid -            else: -                ng = mid -            # print(ok, ng) -        return ok - -    # print(A) -    # print(B) -        idx = meguru_bisect(M + 1, -1, a) -        if 0 <= idx <= M: -            ans = max(ans, i + idx) +        if a > K: +            break +        idx = bisect_right(B, K - a) - 1 +        ans = max(ans, i + idx)