without long longs | Cleanest code maybe
Code
# Code
```cpp []
class Solution {
    static const int MOD = 1e9 + 7;

    static inline int binexp(int a, int b) {
        int res = 1;
        while (b > 0) {
            if (b & 1)
                res = mul(res, a);
            a = mul(a, a);
            b >>= 1;
        }
        return res;
    }

    static inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }

    void computeFacts(vector<int>& facts, const int n) {
        facts[0] = 1;
        for (int i = 1; i <= n; ++i) {
            facts[i] = mul(facts[i - 1], i);
        }
    }

    void computeInverses(vector<int>& inverses, vector<int>& facts,
                         const int n) {
        inverses[0] = 1;
        inverses[n] = binexp(facts[n], MOD - 2);
        for (int i = n - 1; i >= 1; --i) {
            inverses[i] = mul(inverses[i + 1], i + 1);
        }
    }

    int nCr(int n, int r, vector<int>& fact, vector<int>& inv) {
        if (r > n || r < 0)
            return 0;
        int res = fact[n];
        res = mul(res, inv[r]);
        res = mul(res, inv[n - r]);
        return res;
    }

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

        vector<int> factorials(n + 1), inverses(n + 1);
        computeFacts(factorials, n);
        computeInverses(inverses, factorials, n);

        int result = 0;

        for (int i = 0; i < n; ++i) {
            for (int size = 1; size <= k; ++size) {
                int minContribution = mul(
                    nums[i], nCr(n - i - 1, size - 1, factorials, inverses));
                int maxContribution =
                    mul(nums[i], nCr(i, size - 1, factorials, inverses));
                result = (0LL + result + maxContribution +
                          minContribution) %
                         MOD;
            }
        }

        return result;
    }
};
```
['C++']