Easy to understand, window + heap || 12 ms 98%
\nres = []\nw = defaultdict(int)\nfor i in nums[:k]:  # filling dictionary\n\tw[i] += 1\n\n# 1st w count\nh = [(-frq, -num) for num, frq in w.items()]\nheapq.he
```\nres = []\nw = defaultdict(int)\nfor i in nums[:k]:  # filling dictionary\n\tw[i] += 1\n\n# 1st w count\nh = [(-frq, -num) for num, frq in w.items()]\nheapq.heapify(h)\ncnt = x\nsumm = 0\nwhile h and cnt > 0:\n\tfrq, ele = heapq.heappop(h)\n\tsumm += ele * frq\n\tcnt -= 1\nres.append(summ)\n\n# main count & iteration \nfor i in range(k, len(nums)):\n\tnew = nums[i]\n\tif new not in w:\n\t\tw[new] = 1\n\telse:\n\t\tw[new] += 1\n\n\told = nums[i - k]\n\tif w[old] <= 1:\n\t\tdel w[old]\n\telse:\n\t\tw[old] -= 1\n\n\th = [(-frq, -num) for num, frq in w.items()]\n\theapq.heapify(h)\n\tcnt = x\n\tsumm = 0\n\twhile h and cnt > 0:\n\t\tfrq, ele = heapq.heappop(h)\n\t\tsumm += ele * frq\n\t\tcnt -= 1\n\tres.append(summ)\n\nreturn res\n```
['Sliding Window', 'Python', 'Python3']