easy
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
```javascript []
/**
 * @param {number[]} nums
 * @param {number} k
 * @param {number} x
 * @return {number[]}
 */
var findXSum = function (nums, k, x) {
    let answer = [];

    let newMap = new Map()

    for (let num = 0; num <= nums.length - k; num++) {
        let window = nums.slice(num, num + k);
        for (let i = 0; i < window.length; i++) {
            if (newMap.has(window[i])) {
                newMap.set(window[i], newMap.get(window[i]) + 1);
            }
            else {
                newMap.set(window[i], 1);
            }
        }
        let sortedMap = [...newMap].sort((a, b) => {
            if (b[1] == a[1]) return b[0] - a[0]
            return b[1] - a[1];
        });
        let sum = 0;
        for (let i = 0; i < Math.min(x, sortedMap.length); i++) {
            sum += sortedMap[i][0] * sortedMap[i][1];
        }
        answer.push(sum);
        newMap.clear()
    }

    return answer;


};
```
['JavaScript']