defmodule Main do def main do [_, m] = IO.read(:line) |> String.split() |> Enum.map(&String.to_integer/1) IO.read(:line) |> String.split() |> Enum.map(&String.to_integer/1) |> Enum.sort() |> solve(0, 0, m) |> IO.puts() end defp solve(list, last, size, m) do cond do Enum.empty?(list) -> size last + hd(list) <= m -> list |> Enum.slice(1..-1) |> solve(last + hd(list), size + 1, m) true -> list |> Enum.slice(1..-1) |> solve(last, size, m) end end end