python code
Complexity

Time complexity:
O(n⋅klogk)


Space complexity:
O(n+k)

Code


# Complexity
- Time complexity:
$$O(n⋅klogk)$$ 

- Space complexity:
$$O(n+k)$$

# Code
```python3 []
from collections import Counter
class Solution:
    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:
        result = []
        for i in range(0,len(nums)-k+1):
            subarray = nums[i:i+k]
            fre = Counter(subarray)
            sort_fre = sorted(fre.keys(), key=lambda num:(-fre[num],-num))
            filter_num = []
            for j in sort_fre[:x]:
                filter_num.extend([j]*fre[j])
            result.append(sum(filter_num))
        return result
```
['Array', 'Hash Table', 'Sliding Window', 'Python3']