using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }
    //ABC170
    class ProgramA
    {
        public void main()
        {
            //入力
            int a = int.Parse(Console.ReadLine());

            //入力が0ならその位置を答で出す
            Console.WriteLine(a + a*a + a*a*a);

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            int count = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                    count++;
            }

            Console.WriteLine(count);


        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            long k = long.Parse(s[2]);

            long[] one = new long[n + 1];
            long[] two = new long[m + 1];
            long[] dp = new long[m + n];

            string[] s1 = Console.ReadLine().Split(' ');
            string[] s2 = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                if (i == 0)
                    one[i + 1] = long.Parse(s1[i]);
                else
                    one[i + 1] = one[i] + long.Parse(s1[i]);
            }

            for (int i = 0; i < m; i++)
            {
                if (i == 0)
                    two[i + 1] = long.Parse(s2[i]);
                else
                    two[i + 1] = two[i] + long.Parse(s2[i]);
            }

            long ans = 0;
            for(int i = 0;i <= n;i++)
            {
                long time = k - one[i];
                if (time < 0)
                    continue;

                long min = -1;
                long max = m + 1;

                while (min + 1 != max)
                {
                    long t = (min + max) / 2;
                    if (two[t] <= time)
                        min = t;
                    else
                        max = t;
                }

                
                ans = Math.Max(i + min, ans);

            }

            Console.WriteLine(ans);

        }
    }

    class ProgramD
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());

            long ans = 0;
            for (int i = 1; i <= n; i++)
            {
                long count = n / i;
                ans += (i + count * i) * count / 2;

            }

            Console.WriteLine(ans);

           
        }
    }

    class ProgramE
    {

        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            long[] a = new long[n];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(s[i]);

            long sum = a[0] ^ a[1];

            for (int i = 2; i < n; i++)
                sum = sum ^ a[i];

            for (int i = 0; i < n; i++)
                Console.Write((sum ^ a[i]) + " ");

            
        }

        
    }
 
}






Measured memory_bytes: 64452