Priority queue with compared second element ..
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nstruct Compare {\n    bool operator()(pair<int, int>& a, pair<int, int>& b) {\n        if (a.second == b.second) {\n            return a.first < b.first;\n        }\n        return a.second < b.second;\n    }\n};\nclass Solution {\npublic:\n\n\n    vector<int> findXSum(vector<int>& nums, int k, int x) {\n         \n     int n = nums.size();\n        vector<int> answer(n - k + 1);\n        unordered_map<int, int> freqMap;\n\n        for (int i = 0; i < k; ++i) {\n            freqMap[nums[i]]++;\n        }\n\n        auto computeXSum = [&](unordered_map<int, int>& freqMap) -> int {\n            priority_queue<pair<int, int>, vector<pair<int, int>>, Compare> pq;\n\n            for (auto& entry : freqMap) {\n                pq.push(entry);\n            }\n\n            int sum = 0;\n            int count = 0;\n\n            while (!pq.empty() && count < x) {\n                auto [val, freq] = pq.top();\n                pq.pop();\n                sum += val * freq;\n                count++;\n            }\n\n            return sum;\n        };\n\n        answer[0] = computeXSum(freqMap);\n\n        for (int i = 1; i <= n - k; ++i) {\n            int leftElem = nums[i - 1];\n            freqMap[leftElem]--;\n            if (freqMap[leftElem] == 0) {\n                freqMap.erase(leftElem);\n            }\n\n            int newElem = nums[i + k - 1];\n            freqMap[newElem]++;\n\n            answer[i] = computeXSum(freqMap);\n        }\n\n        return answer;\n    }\n};\n```
['Hash Table', 'Heap (Priority Queue)', 'C++']