C++ Frankenstein solution with map and max-heap
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
#include <queue>
#include <utility>
#include <functional>
#include <unordered_map>

class Solution {
    typedef int VAL;
    typedef int FRQ;
    typedef std::pair<VAL,FRQ> PAIR;
public:
    vector<int> findXSum(vector<int>& nums, int k, int x) {
        // Conditions
        if (nums.empty() || k > nums.size()) return {};
        // Initialisation
        std::vector<int> result;
        std::size_t size = nums.size();
        std::unordered_map<VAL,FRQ> umap;
        std::function<bool(const PAIR&, const PAIR&)> MaxHeap = [] (const PAIR &a, const PAIR &b) noexcept(true) -> bool
        {
            if (a.second == b.second)
                return a.first < b.first;
            return a.second < b.second;
        };
        std::priority_queue<PAIR, std::vector<PAIR>, decltype(MaxHeap)> pq(MaxHeap);
        // Implementation
        int start = 0;
        while (k <= size){ 
            // Calculate frequency using a map
            if (umap.empty()){
                for (unsigned int i(start); i < k; ++i){
                    umap[nums[i]]++;
                }
            } else {
                umap[nums[start - 1]]--;
                umap[nums[k - 1]]++;
            }
            //push map data into a max-heap
            // clear first
            while (!pq.empty()) pq.pop();
            for (const auto & pair : umap){
                pq.push(pair);
            }
            int sum = 0;
            for (unsigned int i(0); i < x && !pq.empty(); ++i){
                auto [val, frq] = pq.top();
                sum += (val*frq);
                pq.pop();
            }
            result.emplace_back(sum);
            ++start; ++k;
        }
        // Return result
        return result;
    }
};
```
['C++']