defmodule Main do def lower_bound(list, val, l \\ -1, r \\ -1) do if r == -1 do lower_bound(list, val, l, map_size(list)) else m = div(l + r, 2) if (r - l) <= 1 do r else cond do list[m] < val -> lower_bound(list, val, m, r) list[m] >= val -> lower_bound(list, val, l, m) end end end end def main do toi = &String.to_integer/1 split = &String.split/1 [n, _m, k] = IO.gets("") |> split.() |> Enum.map(toi) [op | b] = IO.gets("") |> split.() b = Enum.map(b, toi) |> Enum.sort |> Enum.with_index |> Enum.reduce(%{}, fn({x, index}, acc) -> Map.put(acc, index, x) end) Enum.map(1..n, fn _ -> a = IO.gets("") |> String.trim |> toi.() if op == "+", do: map_size(b) - lower_bound(b, k-a), else: map_size(b) - lower_bound(b, Float.ceil(k/a)) end) |> Enum.sum |> IO.puts end end