Beats 80% of C++ Users || Solution using Simple Hash Table
Intuition\nMin Heap, Sorting, Hash Table\n\n# Approach\nFirst count the frequency of each element till \'k\' and then perform operation as say in question\n\n# 
# Intuition\nMin Heap, Sorting, Hash Table\n\n# Approach\nFirst count the frequency of each element till \'k\' and then perform operation as say in question\n\n# Complexity\n- Time complexity:\nO(n*logn)\n\n- Space complexity:\nO(n)\n![Screenshot 2024-11-15 224739.png](https://assets.leetcode.com/users/images/dc46fa6e-ef10-4b80-971b-58fe681e2290_1731691224.776664.png)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> findXSum(vector<int>& nums, int k, int x) {\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        vector<int> ans;\n        int u=0;\n        while(k<=n){\n            priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n            for(auto k : mp){\n                pq.push({k.second,k.first});\n                if(pq.size()>x) pq.pop();\n            }\n            int sum=0;\n            while(pq.size()>0){\n                int frq=pq.top().first;\n                int num=pq.top().second;\n                pq.pop();\n                sum+=num*frq;\n            }\n            ans.push_back(sum);\n            k++;\n            if(k>n) break;\n            mp[nums[u]]--;\n            if(mp[nums[u]]==0) mp.erase(nums[u]);\n            mp[nums[k-1]]++;\n            u++;\n        }\n        return ans;\n    }\n};\n```
['Array', 'Hash Table', 'Sliding Window', 'Heap (Priority Queue)', 'C++']