[C++] Well Commented and explained || Simple implementation
Code
# Code
```cpp []
class Solution {
public:
    int minMaxSums(vector<int>& nums, int k) {
        const long long MOD = 1000000007;
        int n = (int)nums.size();
        sort(nums.begin(), nums.end());

        vector<long long> fac(n+1, 1LL), invFac(n+1, 1LL);

        // Fast exponentiation
        auto modExp = [&](long long base, long long exp) {
            long long result = 1;
            while (exp > 0) {
                if (exp & 1) result = (result * base) % MOD;
                base = (base * base) % MOD;
                exp >>= 1;
            }
            return result;
        };

        // Build factorial array
        for (int i = 1; i <= n; i++) {
            fac[i] = (fac[i-1] * i) % MOD;
        }
        invFac[n] = modExp(fac[n], MOD - 2); // (n!)^(MOD-2) mod
        for (int i = n - 1; i >= 0; i--) {
            invFac[i] = (invFac[i + 1] * (i + 1)) % MOD;
        }

        // Helper for nCr
        auto nCr = [&](int N, int R) {
            if (R < 0 || R > N) return 0LL;
            return fac[N] * ((invFac[R] * invFac[N - R]) % MOD) % MOD;
        };

        long long ans = 0;
        for (int i = 0; i < n; i++) {
            // timesAsMin = Sum_{l=1..k} of C(n - i - 1, l - 1)
            long long timesAsMin = 0;
            for (int l = 1; l <= k; l++) {
                timesAsMin = (timesAsMin + nCr(n - i - 1, l - 1)) % MOD;
            }

            // timesAsMax = Sum_{l=1..k} of C(i, l - 1)
            long long timesAsMax = 0;
            for (int l = 1; l <= k; l++) {
                timesAsMax = (timesAsMax + nCr(i, l - 1)) % MOD;
            }

            long long totalAppearance = (timesAsMin + timesAsMax) % MOD;

            // contribution = nums[i] * totalAppearance
            long long contribution = ((long long)nums[i] % MOD) * totalAppearance % MOD;
            ans = (ans + contribution) % MOD;
        }

        return (int)ans;
    }
};

```
['C++']