Elixir - uses :gb_sets
Complexity

Time complexity:
O(n * x log k)


Space complexity:
O(k)

Code
# Complexity
- Time complexity:
 O(n * x log k)

- Space complexity:
O(k)

# Code
```elixir []
defmodule Solution do
  @spec find_x_sum(nums :: [integer], k :: integer, x :: integer) :: [integer]
  def find_x_sum(nums, k, x) do
    freq = Enum.take(nums, k) |> Enum.frequencies()
    count_gb_set = freq |> Enum.map(fn {num, count} -> {count, num} end) |> :gb_sets.from_list()
    first_res_val = find_most_freq_x_nums_sum(count_gb_set, x, 0)
    
    tuple = List.to_tuple(nums)
    length = tuple_size(tuple)
    
    if length <= k do
      [first_res_val]
    else
      for i <- k..(length - 1), reduce: {freq, count_gb_set, [first_res_val]} do
        {freq, count_gb_set, res} ->
          {freq, count_gb_set} = update_window(freq, count_gb_set, elem(tuple, i), elem(tuple, i - k))
          {freq, count_gb_set, [find_most_freq_x_nums_sum(count_gb_set, x, 0) | res]}
      end |> elem(2) |> Enum.reverse()
    end
  end

  defp update_window(freq, count_gb_set, el_to_add, el_to_remove) do
    {freq, count_gb_set} = case Map.get(freq, el_to_add) do
      nil -> 
        {Map.put(freq, el_to_add, 1), :gb_sets.add({1, el_to_add}, count_gb_set)}
      count -> 
        count_gb_set = :gb_sets.delete({count, el_to_add}, count_gb_set)
        {Map.put(freq, el_to_add, count + 1), :gb_sets.add({count + 1, el_to_add}, count_gb_set)}
    end

    case Map.get(freq, el_to_remove) do
      1 -> 
        {Map.delete(freq, el_to_remove), :gb_sets.delete({1, el_to_remove}, count_gb_set)}
      count -> 
        count_gb_set = :gb_sets.delete({count, el_to_remove}, count_gb_set)
        {Map.put(freq, el_to_remove, count - 1), :gb_sets.add({count - 1, el_to_remove}, count_gb_set)}
    end
  end

  defp find_most_freq_x_nums_sum(count_gb_set, x, res) do
    cond do
      :gb_sets.is_empty(count_gb_set) || x == 0 -> res
      true -> 
        {{count, num}, count_gb_set} = :gb_sets.take_largest(count_gb_set)
        find_most_freq_x_nums_sum(count_gb_set, x - 1, res + (count * num))
    end
  end
end
```
['Elixir']