Iterative procedure using dynamic programming
IntuitionApproachComplexity
Time complexity: O(nlogn)+O(n∗k)

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

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

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

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

# Code
```python3 []
class Solution:
    def minMaxSums(self, nums: List[int], k: int) -> int:
        md= 10**9+7

        def solver(arr):
            ret = 0
            dp=[i for i in range(n)]
            for j in range(1,k):
                cs=0
                # print(dp)
                for i in range(j,n):
                    ret = (ret + (dp[i]*arr[i])%md)%md
                    tmp=dp[i]
                    dp[i] = cs
                    cs = (cs + tmp)%md
            return ret
        res = 0
        n=len(nums)
        res = (res + 2*sum(nums))%md
        if(k>1):
            nums.sort()
            res = (res + solver(nums))%md
            nums.reverse()
            res = (res + solver(nums))%md
        
        return res
```
['Python3']