defmodule Main do
  def main do
    [_n, _m, k] = IO.gets("") |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1)

    a_minutes_list =
      IO.gets("") |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1)

    b_minutes_list =
      IO.gets("") |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1)

    next_reading(a_minutes_list, b_minutes_list, k, 0, 0)
    |> IO.puts()
  end

  def next_reading([a_head | a_rest], [], k, amount_time, count) do
    cond do
      amount_time + a_head <= k ->
        next_reading(a_rest, [], k, amount_time + a_head, count + 1)

      true ->
        count
    end
  end

  def next_reading([], [b_head | b_rest], k, amount_time, count) do
    cond do
      amount_time + b_head <= k ->
        next_reading([], b_rest, k, amount_time + b_head, count + 1)

      true ->
        count
    end
  end

  def next_reading([], [], _k, _amount_time, count) do
    count
  end

  def next_reading(
        [a_head | a_rest] = a_minutes_list,
        [b_head | b_rest] = b_minutes_list,
        k,
        amount_time,
        count
      ) do
    if a_head <= b_head do
      cond do
        amount_time + a_head <= k ->
          next_reading(a_rest, b_minutes_list, k, amount_time + a_head, count + 1)

        true ->
          count
      end
    else
      cond do
        amount_time + b_head <= k ->
          next_reading(a_minutes_list, b_rest, k, amount_time + b_head, count + 1)

        true ->
          count
      end
    end
  end
end