DP 
IntuitionApproachComplexity
Time complexity:
O(n∗k)
Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

# Code
```cpp []
class Solution {
public:
    int minMaxSums(vector<int>& nums, int k) {
        int n = nums.size();
        long long mod = 1e9 + 7;

        sort(nums.begin(), nums.end());

        vector<vector<long long>> comb(n + 1, vector<long long>(k + 1, 0));
        comb[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            comb[i][0] = 1;
            for (int j = 1; j <= k; j++) {
                comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
            }
        }

        long long sum_min = 0, sum_max = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= k; j++) {
                if (i + 1 >= j) {
                    sum_min = (sum_min + nums[i] * comb[i][j - 1]) % mod;
                }
            }
            for (int j = 1; j <= k; j++) {
                if (n - i >= j) {
                    sum_max = (sum_max + nums[i] * comb[n - i - 1][j - 1]) % mod;
                }
            }
        }

        return (sum_min + sum_max) % mod;
    }
};

```
['C++']