Using combinatorics (not so optimised)
IntuitionApproachCalculated for a particular element, how many times does it occur in max and in min and calculated result accordingly.Complexity
Time complexit
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
Calculated for a particular element, how many times does it occur in max and in min and calculated result accordingly.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    const int MAX = 1e5+1;
    const int MOD = 1e9+7;
    vector<long long> factorial, inverse_factorial;

    Solution(): factorial(MAX+1), inverse_factorial(MAX+1) {
        precompute();
    }

    void precompute() {
        factorial[0] = inverse_factorial[0] = 1;
        for (int i = 1; i <= MAX; ++i) {
            factorial[i] = (factorial[i - 1] * i) % MOD;
        }
        inverse_factorial[MAX] = power(factorial[MAX], MOD - 2, MOD);
        for (int i = MAX - 1; i > 0; --i) {
            inverse_factorial[i] = (inverse_factorial[i + 1] * (i + 1)) % MOD;
        }
    }

    long long power(long long x, long long y, long long p) {
        long long result = 1;
        x = x % p;
        while (y > 0) {
            if (y % 2 == 1) {
                result = (result * x) % p;
            }
            y = y >> 1;
            x = (x * x) % p;
        }
        return result;
    }

    long long nCr(int n, int r) {
        if (r > n) return 0;
        return (factorial[n] * inverse_factorial[r] % MOD * inverse_factorial[n - r] % MOD) % MOD;
    }

    int minMaxSums(vector<int>& nums, int k) {
        int res=0;
        int n=nums.size();
        sort(nums.begin(), nums.end());
        for(int i=0; i<n; i++){
            long long total= 2;
            for(int j=1; j<k; j++){
                long long maxi=0, mini=0;
                if(i>=j){
                    maxi=(maxi+nCr(i, j))%MOD;
                }
                if(n-1-i>=j){
                    mini=(mini+nCr(n-1-i, j))%MOD;
                }
                total=(total+(maxi+mini)%MOD)%MOD;
            }
            cout<<total<<endl;
            res= (res + (nums[i]*total)%MOD)%MOD;
        }
        return res;
    }
};
```
['C++']