USING PASCAL TRIANGLE TO CALCULATE FACTORIAL.
Code

# Code
```cpp []
class Solution {
public:
    const int mod = 1000000007;

    vector<vector<long long>> compute(int n, int k) {
        vector<vector<long long>> C(n + 1, vector<long long>(k + 1, 0));

        for (int i = 0; i <= n; i++) {
            C[i][0] = 1; 
            for (int j = 1; j <= min(i, k); j++) {
                C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
            }
        }

        return C;
    }

    int minMaxSums(vector<int>& nums, int k) {
        sort(nums.begin(), nums.end());
        int n = nums.size();

        vector<vector<long long>> C = compute(n, k);

        long long ans = 0;
        for (int i = 0; i < n; i++) {
            long long val = 2;
            int x = n - i - 1;

            for (int j = 1; j <= min(x, k - 1); j++) {
                val = (val + C[x][j]) % mod;
            }

            for (int j = 1; j < k && j <= i; j++) {
                val = (val + C[i][j]) % mod;
            }

            ans = (ans + (val * (long long)nums[i]) % mod) % mod;
        }

        return ans;
    }
};

```
['C++']