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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long m = sc.NextLong();
        long k = sc.NextLong();

        long[] a = sc.LongArray();
        long[] b = sc.LongArray();

        long[] sumA = new long[n];
        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                sumA[0] = a[0];
            }
            else
            {
                sumA[i] = sumA[i - 1] + a[i];
            }
        }

        long[] sumB = new long[m];
        for (int i = 0; i < m; i++)
        {
            if (i == 0)
            {
                sumB[0] = b[0];
            }
            else
            {
                sumB[i] = sumB[i - 1] + b[i];
            }
        }

        long answer = 0;

        long posB = m - 1;
        for (int i = 0; i < n; i++)
        {
            while (true)
            {
                if (sumA[i] + sumB[posB] > k)
                {
                    posB--;
                    if (posB < 0)
                    {
                        break;
                    }
                    continue;
                }
                else
                {
                    break;
                }
            }
            if (posB == -1)
            {
                break;
            }
            answer = Math.Max(answer, i + posB + 2);
        }

        long posA = n - 1;
        for (int i = 0; i < m; i++)
        {
            while (true)
            {
                if (sumB[i] + sumA[posA] > k)
                {
                    posA--;
                    if (posA < 0)
                    {
                        break;
                    }
                    continue;
                }
                else
                {
                    break;
                }
            }
            if (posA == -1)
            {
                break;
            }
            answer = Math.Max(answer, i + posA + 2);
        }

        for (int i = 0; i < n; i++)
        {
            if (sumA[i] <= k)
            {
                answer = Math.Max(answer, i + 1);
            }
        }

        for (int i = 0; i < m; i++)
        {
            if (sumB[i] <= k)
            {
                answer = Math.Max(answer, i + 1);
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 73108