[C++] Combinatorics.
For each number determine how many times appear as maximum, lets take x as example, we determine the number of the subsequences which contains x as maximum, the
For each number determine how many times appear as maximum, lets take x as example, we determine the number of the subsequences which contains x as maximum, the subsequnces can be formed only with numbers smaller or equals.The result will be Sum Of Comb(xn, kn-1), combinations of how many numbers are smaller than x taken 1, 2, 3 ..kn-1 (kn-1 beacuse one seat is taken).
The same is for the minimum.

I used the following formula to calculate the number of combinations easily:
![image.png](https://assets.leetcode.com/users/images/eb136a29-822c-4b41-8707-d04af15ca8d9_1737407665.681157.png)

# Code
```cpp []
class Solution {
public:
    int minMaxSums(vector<int>& nums, int k) {
        sort(nums.begin(), nums.end());
        int MOD = 1e9 + 7;
        int n = nums.size();
        vector<vector<int>>cnc(n + 1, vector<int>(k+1, 1));
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j < i && j <= k; j++) {
                if (j == 1) {
                    cnc[i][j] = i;
                } else {
                    cnc[i][j] = (cnc[i-1][j-1]  + cnc[i-1][j]) % MOD;
                }
            }
        }
        long long result = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i && j <= k-1; j++) {
                result += cnc[i][j] * (long long)nums[i]; //maximum is nums[i-1]
                result = result % MOD;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - i && j <= k-1; j++) {
                result += cnc[n - i- 1][j] * (long long)nums[i]; //maximum is nums[i]
                result = result % MOD;
            }
        }
        return result;
    }
};
```
['C++']