#include #include std::vector findXSum(std::vector &nums, int k, int x) { int l = 0; int r = k - 1; std::unordered_map m; std::vector ans; std::vector> temp; int count = 0; for(int i = l;i <= k - 1; ++i){ m[nums[i]] += 1; } for(int i = 0;r < nums.size();++i){ if(i != 0){ } for (const auto& [key, value] : m) { temp.push_back(std::pair(key,value)); } std::sort(temp.begin(),temp.end(),[](std::pair x,std::pair y){ return x.second > y.second; }); for(int i = 0;i < x;i++){ count += temp[i].first * temp[i].second; } ans.push_back(count); temp.clear(); count = 0; } return ans; }