C# | Dictionary | LINQ ORDERBY
Code
# Code
```csharp []
public class CustomComparer : IComparer<KeyValuePair<int,int>>
{
    public int Compare(KeyValuePair<int,int> x, KeyValuePair<int,int> y)
    {
        if(y.Value.CompareTo(x.Value)==1)
            return 1;
        
        if(y.Value.CompareTo(x.Value) == 0)
            return y.Key.CompareTo(x.Key);
        
        return -1;
    }
}
public class Solution {
    public int GetXSum(List<int> arr, int x)
    {
        Dictionary<int,int> dict = new Dictionary<int,int>();
        foreach(var v in arr)
        {
            if(dict.ContainsKey(v))
                dict[v]++;
            else
                dict[v] = 1;
        }
        var sDict = dict.OrderBy(item => item, new CustomComparer());
        int tans = 0;
        int count = 0;
        foreach(var kvp in sDict)
        {
            tans += (kvp.Key*kvp.Value);
            count++;
            if(count == x)
                break;
        }

        return tans;
    }

    public int[] FindXSum(int[] nums, int k, int x)
    {
        List<int> ans = new List<int>();
        List<int> lNums = new List<int>(nums);

        for(int i=0;i<nums.Length-k+1;i++)
        {
            var subArray = lNums.GetRange(i,k);
            int xSum = GetXSum(subArray,x);
            ans.Add(xSum); 
        }

        return ans.ToArray();
    }
}
```
['C#']