defmodule Main do def main do l = IO.read(:line) |> String.trim() |> String.to_integer() IO.read(:line) IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1) |> Enum.sort() |> Enum.reduce_while({0, 0}, fn w, {sum, count} = acc -> if l < sum + w, do: {:halt, acc}, else: {:cont, {sum + w, count + 1}} end) |> elem(1) |> IO.puts() end end