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);


            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) 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;
                }
            }

            long ans = 0;

            var sbb = sb.ToArray();


            for (int i = 0; i < sa.Count; i++)
            {
                var t = LowerBound(sbb, (k - sa[i]));
                // WriteLine("t: {0} i: {1}", t, i);
                if (t < sb.Count && sbb[t] == k - sa[i])
                {
                    // WriteLine("here");
                    t++;

                }
                else if (t == sb.Count)
                {
                    // WriteLine("here2");
                    // t--;
                }
                ans = Max(ans, t  + (i));
            }

            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;
        }
    }
}


Measured memory_bytes: 73068