Easiest Solution in Java
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```java []\nclass Pair{\n    int first;\n    int second;\n    \n    public Pair(int first, int second){\n        this.first = first;\n        this.second = second;\n    }\n}\n\nclass Solution {\n    public int[] findXSum(int[] nums, int k, int x) {\n        int n = nums.length;\n        \n        int[] ans = new int[n-k+1];\n        for(int i=0; i<n-k+1; i++){\n            Map<Integer, Integer> map = new HashMap<>();\n            for(int j=i; j<i+k; j++){\n                map.put(nums[j], map.getOrDefault(nums[j], 0)+1);\n            }\n            \n            List<Pair> list = new ArrayList<>();\n            for(int key:map.keySet()){\n                list.add(new Pair(map.get(key), key));\n            }\n            Collections.sort(list, (Pair a, Pair b)->{\n                if(a.first==b.first){\n                    return b.second-a.second;\n                }\n                return b.first-a.first;\n            });\n            \n            int sum = 0;\n            int uniq = 0;\n            for(Pair l:list){\n                if(uniq >= x){\n                    break;\n                }\n                \n                sum += l.first*l.second;\n                uniq++;\n            }\n            ans[i]=sum;\n        }\n        return ans;\n    }\n}\n```
['Java']