Easy to understand C++ Solution
Complexity\n- Time complexity: O(n*x(log m))\n\n- Space complexity: O(m)\n\n# Code\ncpp []\nclass Solution {\nprivate:\n    int f(int x, unordered_map<int,int> 
# Complexity\n- Time complexity: O(n*x(log m))\n\n- Space complexity: O(m)\n\n# Code\n```cpp []\nclass Solution {\nprivate:\n    int f(int x, unordered_map<int,int> &mp){\n        priority_queue<pair<int,int>> pq;\n        for(auto &it: mp) pq.push({it.second, it.first});\n        int ans = 0;\n        while(!pq.empty() && x != 0){\n            int val = pq.top().second;\n            int freq = pq.top().first;\n            pq.pop();\n            ans += (val*freq);\n            x--;\n        }\n        return ans;\n    }\npublic:\n    vector<int> findXSum(vector<int>& nums, int k, int x) {\n        vector<int> ans;\n        int n = nums.size();\n        unordered_map<int,int> mp;\n        for(int i = 0; i < k; i++){\n            mp[nums[i]]++;\n        }\n        ans.push_back(f(x, mp));\n        for(int i = k; i < n; i++){\n            mp[nums[i-k]]--;\n            if(mp[nums[i-k]] == 0) mp.erase(nums[i-k]);\n            mp[nums[i]]++;\n            ans.push_back(f(x, mp));\n        }\n        return ans;\n    }\n};\n```
['Array', 'Hash Table', 'Sliding Window', 'Heap (Priority Queue)', 'C++']