Combinatorics
IntuitionApproachf(i)=>no of ways to pick atmost k elemets from i elementsComplexity
Time complexity:

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

# Approach
<!-- Describe your approach to solving the problem. -->
f(i)=>no of ways to pick atmost k elemets from i elements

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

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

# Code
```python3 []
MOD1 = 10**9 + 7
fact =[1]
inv = [1]
for i in range(1,10**6+1):
    fact.append(pow(fact[-1]*i,1,MOD1))
    inv.append(pow(fact[-1],-1,MOD1))
class Solution:
    def minMaxSums(self, nums: List[int], k: int) -> int:
        k-=1
        @cache
        def f(i):
            if i<=k:
                return 2**i
            return (2*f(i - 1) - (fact[i-1]*inv[k]*inv[i -k - 1]))%MOD1
        nums.sort()
        N = len(nums)
        ans = 0 
        for i in range(N):
            ans+= nums[i]*(f(N - i - 1))
            ans+= nums[i]*(f(i))
            ans%=MOD1            
        return ans%MOD1
```
['Python3']