defmodule Main do def main do l = IO.gets("") |> String.trim |> String.to_integer _ = IO.gets("") w = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer(&1)) |> Enum.sort sum(w, 0, l, 0) |> IO.puts end def sum([], _, _, count) do count end def sum([head | tail], total, l, count) when total+head <= l do sum(tail, total + head, l, count+1) end def sum(_, _, _, count) do count end end