defmodule Main do def main() do l = IO.gets("") |> String.trim |> String.to_integer n = IO.gets("") |> String.trim |> String.to_integer w = IO.gets("") |> String.trim |> String.split |> Enum.map(fn x -> String.to_integer(x) end) |> Enum.sort IO.inspect n - calc(0, w, l) end defp calc(c, w, l) do if Enum.count(w) > 0 do h = hd w t = tl w cond do c + h <= l -> calc(c + h, t, l) true -> Enum.count(t) + 1 end end 0 end end