concise solution using combinatrics
ApproachWe need to find contribution each index will have.
Since we are calculating subsequences order doesnt matter. We will sort the array.
num[i] in sorted a
# Approach
<!-- Describe your approach to solving the problem. -->
We need to find contribution each index will have.
 Since we are calculating subsequences order doesnt matter. We will sort the array. 
num[i] in sorted array will be the maximum for the subsequnces that can be constructed from the array between nums[0] and nums[i - 1] and it will be minimum for range between nums[i + 1] and nums[n - 1].
 
The total of number of times nums[i] is maximum would be the same as nums[n - i - 1] is minimum.
So we need to find ways to choose atmost k elements from the number of elements in which nums[i] is the smallest and nums[n - i - 1] is the maximum which woould be find number of ways to choose at most k - 1 (as we wont be including the element whose contribution we are finding) elements from number of elemnents from we can choose.

# Complexity
- Time complexity:O(n * k)

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

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

# 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 ++) {
            int numberOfSubsequences = 0;
            for(int r = 0; r <= k - 1; r ++) 
                if(n >= r) numberOfSubsequences = (numberOfSubsequences + ncr[n][r]) % MOD;
            ans = (ans + (long long)(nums[n] + nums[nums.size() - n - 1]) * numberOfSubsequences) % MOD;
        }
        return ans;
    }
};
```
['C++']