🚨 C++ || Map Sort Calculate || O(n)
Intuition\n- Index value to count\n- Reverse index count to value\n- Calculate top\n\nCode\nc++\nvector<int> findXSum(vector<int>& nums, int k, int upto) {\n   
**Intuition**\n- Index value to count\n- Reverse index count to value\n- Calculate top\n\n**Code**\n```c++\nvector<int> findXSum(vector<int>& nums, int k, int upto) {\n    int n = nums.size();\n    vector<int> res; k--;\n    \n    map<int, int> track;\n    auto get_sum = [&]() {\n        vector<pair<int, int>> r;\n        for (auto [x, count]: track) r.emplace_back(count, x);\n        sort(r.begin(), r.end(), greater<pair<int, int>>());\n        \n        int sum = 0;\n        for (auto j = 0; j < min( (int) r.size(), upto); j++)  \n            sum += r[j].first * r[j].second;\n        return sum;\n    };\n    \n    for (auto i = 0; i < n; i++) {\n        track[nums[i]]++;\n        if (i >= k) \n            res.push_back(get_sum()),\n            track[nums[i - k]]--;\n    }\n    return res;\n}\n```\n\n**Complexity**\n`Time`: O(nlogn)\n`Space`: O(n)\n\n**For more solutions and concepts, check out this \uD83D\uDCD6 [BLOG](https://github.com/MuhtasimTanmoy/notebook)  and  \uD83C\uDFC6 [GITHUB REPOSITORY](https://github.com/MuhtasimTanmoy/playground) with over 2000+ solutions.**
[]