Easy to understand approach.
ApproachSorting elements
Then for each element, consider all subsequences for which current element can be maximum and minimum.
Calculating sum of value of curr
# Approach
<!-- Describe your approach to solving the problem. -->
Sorting elements
Then for each element, consider all subsequences for which current element can be maximum and minimum.
Calculating sum of value of current element*number of subsequences.

# Code
```cpp []
class Solution {
public:
    int minMaxSums(vector<int>& nums, int k) {
        sort(nums.begin(), nums.end());
        int ans = 0;
        int MOD = 1e9 + 7;
        vector<vector<int>> ncr(nums.size() + 1, vector<int> (k + 1,0));
        
        ncr[0][0] = 1;
        for (int n = 1; n <= nums.size(); n++) {
            ncr[n][0] = 1;
            for (int r = 1; r <= k; r++) 
                ncr[n][r] = (ncr[n - 1][r - 1] + ncr[n - 1][r]) % MOD;
        }
        for(int n = 0; n < nums.size(); n ++)
        {
            long long comb= 0;

            //for all left element, it is Max. So finding all subsequences possible on left.
            for(int r= 0;r<=min(n, k-1);r++)
                comb= (comb + ncr[n][r])%MOD;
            
            //for all right element, it is Min. So finding all subsequences possible on right.
            for(int r= 0;r<=min((int)nums.size()-n-1, k-1);r++)
                comb= (comb + ncr[nums.size()-n-1][r])%MOD;
            
            ans= (ans+(nums[n]*comb))%MOD;
        }
        
        return ans;
    }
};
```
['C++']