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

namespace abc172
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc172C2();
            Console.Out.Flush();
        }

        //https://atcoder.jp/contests/abc172/submissions/14749792
        public static void solve_abc172C2()
        {
            long[] nmk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long n = nmk[0];
            long m = nmk[1];
            k = nmk[2];
            long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long[] b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long aSum = 0;
            for (int i = 0; i < n; i++)
            {
                aSum += a[i];
            }
            long bSum = 0;
            long j = 0;
            long ans = 0;
            for (long i = n; i >= 0; i--)
            {
                if (i < n)
                {
                    aSum -= a[i];
                }
                if (aSum <= k)
                {
                    while (j < m && aSum + bSum + b[j] <= k)
                    {
                        bSum += b[j];
                        j++;
                    }
                    ans = Math.Max(ans, i + j);
                }
            }

            Console.WriteLine(ans);
        }
        /*
        Increment in the parameters doesn't work in recursive calls
        Example:
        getTotal(cnt++);
        Should be gettotal(cnt + 1);
        */
        public static long getTotal(long sum, long cnt, long idx1, long idx2)
        {
            if (idx1 < a.Length)
            {
                if (sum + a[idx1] < k)
                {
                    total = Math.Max(total, getTotal(sum + a[idx1], cnt + 1, idx1 + 1, idx2));
                }
            }
            if (idx2 < b.Length)
            {
                if (sum + b[idx2] < k)
                {
                    total = Math.Max(total, getTotal(sum + b[idx2], cnt + 1, idx1, idx2 + 1));
                }
            }
            return cnt;
        }

        public static long[] a;
        public static long[] b;
        public static long k;
        public static long total = 0;
        public static void solve_abc172C()
        {
            long[] nmk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long n = nmk[0];
            long m = nmk[1];
            k = nmk[2];
            a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            Console.WriteLine(getTotal(0, 0, 0, 0));
            /*long min = 0;
            long cnt = 0;
            long i = 0;
            long j = 0;
            while (i < n || j < m)
            {
                if (i >= n && j < m)
                {
                    if (min + b[j] <= k)
                    {
                        min += b[j];
                        cnt++;
                    }
                    j++;
                }
                else if (j >= m && i < n)
                {
                    if (min + a[i] <= k)
                    {
                        min += a[i];
                        cnt++;
                    }
                    i++;
                }
                else
                {
                    if (min + Math.Min(a[i], b[j]) <= k)
                    {
                        min += Math.Min(a[i], b[j]);
                        cnt++;
                    }
                    else
                    {
                        break;
                    }  

                    if (a[i] < b[j])
                    {
                        i++;
                    }
                    else
                    {
                        j++;
                    }
                }
            }
            Console.WriteLine(cnt);
            */
        }

        public static void solve_abc172B()
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int cnt = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc172A()
        {
            int a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3));
        }
    }
}

Measured memory_bytes: 70136