using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMK = GetInput_long();
            var fulltime = NMK[2];

            var a_list = GetInput_long();
            var b_list = GetInput_long();

            var a_lengthList = new List<long>();
            var b_lengthList = new List<long>();
            a_lengthList.Add(0);
            b_lengthList.Add(0);
            long tempsum = 0;
            for (int i = 0; i < a_list.Length; i++)
            {
                tempsum += a_list[i];
                if (tempsum > fulltime) break;
                a_lengthList.Add(tempsum);
            }
            tempsum = 0;
            for (int i = 0; i < b_list.Length; i++)
            {
                tempsum += b_list[i];
                if (tempsum > fulltime) break;
                b_lengthList.Add(tempsum);
            }

            int nowMax = 0;
            int b_index_now = 0;
            for(int i = a_lengthList.Count-1; i >= 0; i--)
            {
                long remainTime = fulltime - a_lengthList[i];
                while (true)
                {
                    if (b_lengthList.Count-1 <= b_index_now) break;
                    var check = b_lengthList[b_index_now + 1];
                    if (check <= remainTime) b_index_now++;
                    else break;
                }
                var sum = (i + b_index_now);
                if (nowMax < sum) nowMax = sum;
                if (b_lengthList.Count-1 <= b_index_now) break;//もう減るだけ
            }
            Console.WriteLine(nowMax);
        }

        #region input


        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion
        
    }
}

Measured memory_bytes: 69476