Heap + Sliding Window
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
```python3 []
class Solution:
    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:
        size, dd, result, left = len(nums), defaultdict(int), [], 0
        
        def calculate_nlargest(n, d):
            heap = []
            result = 0
            for k, v in d.items():
                heappush(heap, (v, k))
                if len(heap) > n:
                    heappop(heap)
            while heap:
                x, y = heappop(heap)
                result += x * y
            return result
            
        for right in range(size):
            dd[nums[right]] += 1
            if right == k - 1:
                result.append(calculate_nlargest(x, dd))
            elif right >= k:
                dd[nums[left]] -= 1
                left += 1
                result.append(calculate_nlargest(x, dd))

        return result
```
['Python3']