BEST PYTHON SOLUTION WITH 84MS OF RUNTIME !
\n# Code\npython3 []\nclass Solution:\n    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:\n        from collections import Counter\n        i
\n# Code\n```python3 []\nclass Solution:\n    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:\n        from collections import Counter\n        import heapq\n        \n        def x_sum(subarray):\n            freq = Counter(subarray)\n            # Get the top x most frequent elements\n            most_common = heapq.nlargest(x, freq.items(), key=lambda item: (item[1], item[0]))\n            # Sum of the elements, keeping only top x frequent ones\n            result = sum(value * count for value, count in most_common)\n            return result\n\n        result = []\n        for i in range(len(nums) - k + 1):\n            subarray = nums[i:i + k]\n            result.append(x_sum(subarray))\n\n        return result\n\n```
['Python3']