Java | Efficient Solution | Easy to understand 
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution { 
    public int[] findXSum(int[] nums, int k, int x) {
        int [] resultArr = new int[nums.length-k+1];
        for(int i =0; i<resultArr.length;i++){
            Map<Integer,Integer> map = new HashMap<>();
            int left = i;
            while(left<k+i){
                map.put(nums[left],map.getOrDefault(nums[left++],0)+1);
            }
                PriorityQueue<Map.Entry<Integer,Integer>> pq = new PriorityQueue<>(
                (a,b)->{
                    if(a.getValue()==b.getValue()){
                        return b.getKey()-a.getKey();
                    }
                    return b.getValue()-a.getValue();
                }
                );
                for(Map.Entry<Integer,Integer> entry : map.entrySet()){
                    pq.add(entry);
                }
                int currSum=0;
                for(int j=0; j<x; j++){
                Map.Entry<Integer,Integer> num = pq.poll();
                if(num != null){
                    currSum += num.getValue()*num.getKey();
                }
                }
                resultArr[i] = currSum;

        }
        return resultArr;
    }
}
```
['Java']