using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC172
{
    class MainClass
    {

        static long[] s, a, b;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            a = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            b = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long n = s[0];
            long m = s[1];
            long k = s[2];

            var sa = new List<long>();
            var sb = new List<long>();
            sa.Add(0);
            sb.Add(0);


            long atmp = 0;
            long btmp = 0;

            bool aover = false;
            bool bover = false;

            for (long i = 0; i <= Max(m, n); i++)
            {
                if (!aover && !bover)
                {
                    atmp += a[i];
                    if (atmp <= k)
                    {
                        sa.Add(atmp);
                        
                        if (i == n-1 ) {
                            // WriteLine("here i:{0}",i);
                            aover = true;
                        }
                    }
                    else
                    {
                        aover = true;
                    }
                    btmp += b[i];
                    if (btmp <= k)
                    {
                        sb.Add(btmp);
                        if (i == m-1 ) bover = true;
                    }
                    else
                    {
                        bover = true;
                    }
                }
                else if (!aover)
                {
                    atmp += a[i];
                    if (atmp <= k)
                    {
                        sa.Add(atmp);
                        if (i == n-1 ) aover = true;
                    }
                    else
                    {
                        aover = true;
                    }
                }
                else if (!bover)
                {
                    btmp += b[i];
                    if (btmp <= k)
                    {
                        sb.Add(btmp);
                        if (i == m-1 ) bover = true;
                    }
                    else
                    {
                        bover = true;
                    }
                }
                else
                {
                    break;
                }
            }
            
            // sa.ForEach(WriteLine);
            // sb.ForEach(WriteLine);

            long ans = 0;

            var sbb = sb.ToArray();
            int nowb = 0;
            for(int i = sa.Count-1;i>=0;i--){
                long readlife = k-sa[i];
                for(int j = nowb;j<sb.Count;j++){
                    
                    if(readlife-sb[j]<0){
                        nowb = j - 1;
                        break;
                    }else if(readlife-sb[j] == 0){
                        nowb = j;
                        break;
                    }else{
                        nowb = j;
                    }             
                }
                // WriteLine("i : {0} nowb : {1}",i,nowb);
                ans = Max(ans,i+nowb);
            }
            WriteLine(ans);





        }
        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}


Measured memory_bytes: 73132