C#
You need to know some Math knowledge Fermat's little theoremCode
You need to know some Math knowledge [Fermat's little theorem](https://en.wikipedia.org/wiki/Fermat%27s_little_theorem)

# Code
```csharp []
public class Solution {
            const int MOD = 1_000_000_007;
            const int MX = 100_001; 

            private long[] F = new long[MX]; // F[i] = i!
            private long[] INV_F = new long[MX]; // INV_F[i] = i!^-1
            public int MinMaxSums(int[] nums, int k)
            {
                F[0] = 1;
                for (int i = 1; i < MX; i++)
                {
                    F[i] = F[i - 1] * i % MOD;
                }
                INV_F[^1] = pow(F[^1], MOD - 2);
                for (int i = MX - 1; i >= 1; i--)
                {
                    INV_F[i - 1] = INV_F[i] * i % MOD;
                }
                Array.Sort(nums);
                long ans = 0;
                for (int i = 0; i < nums.Length; i++)
                {
                    long s = 0;
                    for (int j = 0; j < Math.Min(k, i + 1); j++)
                    {
                        s += comb(i, j);
                    }
                    ans = (ans + s % MOD * (nums[i] + nums[nums.Length - 1 - i])) % MOD;
                }
                return (int)ans;
            }

            private long comb(int i, int j)
            {
                return F[i] * INV_F[j] % MOD * INV_F[i - j] % MOD;
            }

            public long pow(long x, int n)
            {
                long res = 1;
                for (; n > 0; n >>= 1)
                {
                    if ((n & 1) == 1)
                    {
                        res = res * x % MOD; ;
                    }
                    x = x * x % MOD;
                }
                return res;
            }
}
```
['C#']