defmodule Main do def main do 1..3 |> Enum.map(fn _ -> IO.read(:line) |> String.trim() end) |> (fn [n, c, s] -> [ n |> String.to_integer(), c |> String.split() |> Enum.map(&String.to_integer/1), s |> String.split() |> Enum.map(&String.to_integer/1) ] end).() |> solve |> IO.puts() end def solve([n, c, s]) do solve_rec(0..(n - 1) |> Enum.to_list(), c, s, List.duplicate(0, 100), 0) end def solve_rec([], _, _, v, k) do cond do k < v |> Enum.max() -> "NO" true -> "YES" end end def solve_rec(n, c, s, v, k) do cond do s |> Enum.at(n |> hd) == 0 -> solve_rec(n |> tl, c, s, v, k + (c |> Enum.at(n |> hd))) true -> solve_rec( n |> tl, c, s, v |> List.update_at( (s |> Enum.at(n |> hd)) - 1, &(&1 + (c |> Enum.at(n |> hd))) ), k ) end end end