Combinatorics | C++
The intuition behind my solution is the basic concepts of combinatorics.Initially we sort the array. Then, for each index i, we find the number of subsequences
The intuition behind my solution is the basic concepts of combinatorics. 

Initially we sort the array. Then, for each index i, we find the number of subsequences in which the number nums[i] will be the minimum and maximum.

For calculating the possible ways I used this formula/intuition:
Let left be the number of elements to the left of index i and right be the number of elements to the right of index. 
Number of subsequences of size j where nums[i] is maximum = leftCj 
Number of subsequences of size j where nums[i] is minimum = rightCj 
Here, C represents nCr from Combinatorics.

As the question all the subsequences of size atmost k, we run this for j = 1 to j = k for all the indices.

Note: To compute nCr, we require factorials and inverse factorials, I used a boilerplate code coz I'm lazy to code all that during a contest. You can look up how to compute nCr and factorials efficiently in google.

# Code
```cpp []
class Solution {
public:
    int MOD = 1e9+7;
    long long modExp(long long x, long long y, int mod) {
        long long result = 1;
        while (y > 0) {
            if (y % 2 == 1)
                result = (result * x) % mod;
            x = (x * x) % mod;
            y /= 2;
        }
        return result;
    }
    
    void precomputeFactorials(vector<long long>& fact, vector<long long>& invFact, int maxN) {
        fact[0] = 1;
        for (int i = 1; i <= maxN; i++) {
            fact[i] = (fact[i - 1] * i) % MOD;
        }
        invFact[maxN] = modExp(fact[maxN], MOD - 2, MOD);
        for (int i = maxN - 1; i >= 0; i--) {
            invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
        }
    }
    
    long long nCr(int n, int r, const vector<long long>& fact, const vector<long long>& invFact) {
        if (r > n || r < 0) return 0;
        return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;
    }
    int minMaxSums(vector<int>& nums, int k) {
        int n = nums.size();
        sort(nums.begin(), nums.end());
        vector<long long> fact(n + 1), invFact(n + 1);
        precomputeFactorials(fact, invFact, n);
        
        long long ans = 0;
        for(int i = 0; i < n; i++){
            long long ways = 0;
            long long left = i;
            long long right = n-1-i;
            
            for(int j = 1; j <= k; j++){
                if(right >= j-1){
                    ways += nCr(right, j-1, fact, invFact);
                }
                if(left >= j-1){
                    ways += nCr(left, j-1, fact, invFact);
                }
            }
            // cout << nums[i] << " " << ways << endl;
            long long temp = (ways%MOD * nums[i]%MOD) % MOD;
            ans = (ans%MOD + temp%MOD) % MOD;
        }
        return ans;
    }
};
```
['C++']