Easy solution brute force
Code\njava []\nclass Solution {\n    class Pair{\n        int val;\n        int count;\n\n        Pair(int a, int b){\n            val = a;\n            count =
# Code\n```java []\nclass Solution {\n    class Pair{\n        int val;\n        int count;\n\n        Pair(int a, int b){\n            val = a;\n            count = b;\n        }\n    }\n\n    public int[] findXSum(int[] nums, int k, int x) {\n        int n = nums.length;\n\n        int j = 0;\n        int[] ans = new int[n-k+1];\n        for(int i=k-1;i<n;i++){\n            ans[j] = helper(nums, j, i, x);\n            j++;\n        }\n        return ans;\n    }\n\n    public int helper(int[] arr, int low, int high, int x){\n        PriorityQueue<Pair> pq = new PriorityQueue<>((a,b)->(b.count==a.count?b.val-a.val:b.count-a.count));\n        HashMap<Integer, Integer> map = new HashMap<>();\n        int sum = 0;\n        for(int i=low;i<=high;i++){\n            sum += arr[i];\n            map.put(arr[i], map.getOrDefault(arr[i], 0)+1);\n        }\n        if(map.size()<x){\n            return sum;\n        }\n        sum = 0;\n\n        for(Map.Entry<Integer,Integer> it : map.entrySet()){\n            pq.add(new Pair(it.getKey(), it.getValue()));\n        }\n\n        int ct = 0;\n        while(ct!=x && pq.size()!=0){\n            Pair p = pq.poll();\n            sum += p.val*p.count;\n            ct++;\n        }\n        return sum;\n    }\n}\n```
['Array', 'Hash Table', 'Sliding Window', 'Heap (Priority Queue)', 'Java']