c++() sorting & Pascale`s treangle
IntuitionApproachComplexity
Time complexity:

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)$$ -->

- Space complexity:
<!-- 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());
    
    vector<vector<long>> C(nums.size(), vector<long>(k, 1));
    for(int i = 2; i < nums.size(); ++i)
      for(int j = 1, lim = min(i, k); j < lim; ++j) C[i][j] = (C[i-1][j] + C[i-1][j-1]) % 1000000007;

    long res = 0;

    for(int i = 0; i != nums.size(); ++i){
      for(int j = 0; i - j >= 0 && j < k; ++j)
        res = (res + C[i][j] * nums[i]) % 1000000007;

      for(int j = 0, m = nums.size() - i - 1, h = i;  h < nums.size() && j < k; ++j, ++h)
        res = (res + C[m][j] * nums[i]) % 1000000007;
    }

    return (int)res;      
  }
};
```
['C++']