Create NodeFreq class(contain compare)
IntuitionNot sure why search tuple item in sortedset doesn't work properly. Create a new class and keep updating is an acceptable way.ApproachComplexity
Time co
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Not sure why search tuple item in sortedset doesn't work properly. Create a new class and keep updating is an acceptable way.
# 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
```csharp []
public class Solution {
    public class NodeFreq
    {
        public int Val;
        public int Freq;

        public NodeFreq(int val, int freq)
        {
            Val = val; 
            Freq = freq;
        }

    }

    public class NodeFSort : IComparer<NodeFreq>
    {
        public int Compare(NodeFreq a, NodeFreq b)
        {
            if (a.Freq != b.Freq)
                return b.Freq > a.Freq ? 1 : -1;

            return b.Val > a.Val ? 1 : -1;
        }
    }
    private int SumX(List<NodeFreq> sSet, int x)
    {
        int sum = 0;
        foreach (var cur in sSet)
        {
            sum += cur.Val * cur.Freq;
            if (--x == 0)
                break;
        }

        return sum;
    }

    private int FindIdx(List<NodeFreq> l, int val)
    {
        for (int i = 0; i < l.Count; i++)
        {
            if (l[i].Val == val)
                return i;
        }

        return -1;
    }

    public int[] FindXSum(int[] nums, int k, int x) {
        int len = nums.Length;
        List<NodeFreq> sortedSet = new List<NodeFreq>();
        int firstPart = Math.Min(k, len);
        Dictionary<int, int> dict = new();

        for (int i = 0; i < firstPart; i++)
        {
            if (!dict.ContainsKey(nums[i]))
                dict.Add(nums[i], 1);
            else
                dict[nums[i]]++;
        }

        foreach (var kvp in dict)
        {
            sortedSet.Add(new NodeFreq(kvp.Key, kvp.Value));
        }

        int[] res = new int[len - k + 1];
        for (int i = 0; i < res.Length; i++)
        {
            sortedSet.Sort(new NodeFSort());
            res[i] = SumX(sortedSet, x);

            if (i == res.Length - 1)
                break;

            int next = nums[i + k];
            if (dict.ContainsKey(next))
            {
                int idx = FindIdx(sortedSet, next);
                sortedSet.RemoveAt(idx);
                dict[next]++;
            }
            else
            {
                dict.Add(next, 1);
            }

            sortedSet.Add((new NodeFreq(next, dict[next])));

            var remIdx = FindIdx(sortedSet, nums[i]);
            sortedSet.RemoveAt(remIdx);

            if (--dict[nums[i]] == 0)
            {
                dict.Remove(nums[i]);
            }
            else
            {
                sortedSet.Add(new NodeFreq(nums[i], dict[nums[i]]));
            }
        }

        return res;
    }
}
```
['C#']