def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)



def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)



from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

import math

from fractions import gcd

import random

import string

import copy

from itertools import combinations, permutations, product

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7



#############

# Main Code #

#############



def or_less(array, x):

    # arrayの中のx以下のものの個数

    # arrayの中のx以下のもののうちの最大値

    index = bisect_right(array, x)

    if index == 0:

        or_less_int = -float('inf')

    else:

        or_less_int = array[index - 1]

    return [index, or_less_int]



N, M, K = getNM()

A = getList()

A.insert(0, 0)

B = getList()



A_imos = copy.deepcopy(A)

for i in range(N):

    A_imos[i + 1] += A_imos[i]



B_imos = copy.deepcopy(B)

for i in range(M - 1):

    B_imos[i + 1] += B_imos[i]



ans = 0

for i in range(N + 1):

    if A_imos[i] > K:

        continue

    index = or_less(B_imos, K - A_imos[i])[0]

    ans = max(ans, i + index)

print(ans)
def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)



def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)



from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

from math import sqrt

from fractions import gcd

import random

import string

import copy

from itertools import combinations, permutations, product

from operator import mul, itemgetter

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7



#############

# Main Code #

#############



N, M, K = getNM()

A = [0] + getList()

B = [0] + getList()



total = K

b_left = sum(B)

l = M



ans = 0

# Aがright番目まで進んだ時

for r in range(N + 1):

    total -= A[r]

    # Aの本を取りすぎる場合は飛ばす

    if total < 0:

        continue

    # 合計total以下になるまで戻る

    while total < b_left:

        b_left -= B[l]

        l -= 1

    ans = max(ans, l + r)

print(ans)
def getN():
    return int(eval(input()))


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


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


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


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


def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)


def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]


def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)


def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)


from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
def or_less(array, x):
    # arrayの中のx以下のものの個数
    # arrayの中のx以下のもののうちの最大値
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float("inf")
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]


N, M, K = getNM()
A = getList()
A.insert(0, 0)
B = getList()
A_imos = copy.deepcopy(A)
for i in range(N):
    A_imos[i + 1] += A_imos[i]
B_imos = copy.deepcopy(B)
for i in range(M - 1):
    B_imos[i + 1] += B_imos[i]
ans = 0
for i in range(N + 1):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, i + index)
print(ans)

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


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


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


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


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


def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)


def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]


def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)


def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)


from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N, M, K = getNM()
A = [0] + getList()
B = [0] + getList()
total = K
b_left = sum(B)
l = M
ans = 0
# Aがright番目まで進んだ時
for r in range(N + 1):
    total -= A[r]
    # Aの本を取りすぎる場合は飛ばす
    if total < 0:
        continue
    # 合計total以下になるまで戻る
    while total < b_left:
        b_left -= B[l]
        l -= 1
    ans = max(ans, l + r)
print(ans)

-import math +from math import sqrt -from operator import mul +from operator import mul, itemgetter -def or_less(array, x): -    # arrayの中のx以下のものの個数 -    # arrayの中のx以下のもののうちの最大値 -    index = bisect_right(array, x) -    if index == 0: -        or_less_int = -float("inf") -    else: -        or_less_int = array[index - 1] -    return [index, or_less_int] - - -A = getList() -A.insert(0, 0) -B = getList() -A_imos = copy.deepcopy(A) -for i in range(N): -    A_imos[i + 1] += A_imos[i] -B_imos = copy.deepcopy(B) -for i in range(M - 1): -    B_imos[i + 1] += B_imos[i] +A = [0] + getList() +B = [0] + getList() +total = K +b_left = sum(B) +l = M -for i in range(N + 1): -    if A_imos[i] > K: +# Aがright番目まで進んだ時 +for r in range(N + 1): +    total -= A[r] +    # Aの本を取りすぎる場合は飛ばす +    if total < 0: -    index = or_less(B_imos, K - A_imos[i])[0] -    ans = max(ans, i + index) +    # 合計total以下になるまで戻る +    while total < b_left: +        b_left -= B[l] +        l -= 1 +    ans = max(ans, l + r)