Contribution technique solution
IntuitionAs we need Subsequences, so the orientation of array is not important, we can disorient the array, hence there comes an intuition for sorting the array
# Intuition
As we need Subsequences, so the orientation of array is not important, we can disorient the array, hence there comes an intuition for sorting the array, now as we have sorted the array the maximum element will always be at the right most element and smallest will be the left most. Now we can use contribution of each element in the solution.
there are 2 power n(2^n) subsequences of array (take not take), and we also know nc0+nc1+nc2+nc3+.....ncn=2^n
lets move towards the approach

# Approach
if we select an element in sorted array, it will always be smallest with compared to all elements on right and larger than all elements on left. so when we take any subsequence where that element is part of subsequnce and all other elements are on the left or right , it will contribute as smallest and largest accordingly. So we iterate from 0 to min(k-1,left Elements) total subsequences and 0 to min(k-1, right Elements) and multiply with the number so we get a total contribution of that element.

# Complexity
- Time complexity:
the pre calculation will take O(n)+solution calculation will take O(n*k)
therefore total=o(n*k)
- Space complexity:
O(n)

# Code
```cpp []
#define ll long long
class Solution {
public:
    #define mod 1000000007
    #define MAXN 100010
    ll binpow(ll a,ll p){
        ll ans=1;
        while(p){
            if(p%2){
                ans=(ans*a)%mod;
            }
            p>>=1;
            a=(a*a)%mod;
        }
        return ans;
    }
    ll fact[MAXN+1]{},invFact[MAXN+1]{};
    void pre(){
        fact[0]=1;
        for(ll i=1;i<=MAXN;i++){
            fact[i]=(fact[i-1]*i)%mod;
        }
        invFact[MAXN]=binpow(fact[MAXN],mod-2);
        for(ll i=MAXN-1;i>=0;i--){
            invFact[i]=((i+1)*invFact[i+1])%mod;
        }
    }
    ll ncr(ll n,ll r){
        if(r>n||r<0)return 0;
        if(r==0||n==r)return 1;
        return (fact[n]*((invFact[n-r]*invFact[r])%mod))%mod;
    }
    int minMaxSums(vector<int>& nums, int k) {
        pre();
        ll K=k;
        ll sum=0;
        sort(nums.begin(),nums.end());
        ll n=nums.size();
        for(ll i=0;i<n;i++){
            ll left=i;
            ll right=n-1-i;
            ll t1=0;
            ll t2=0;
            for(ll j=0;j<=min(left,K-1);j++){
                t1=(t1+(ncr(left,j)*nums[i])%mod)%mod;
            }
            for(ll j=0;j<=min(right,K-1);j++){
                t2=(t2+(ncr(right,j)*nums[i])%mod)%mod;
            }
            // cout<<i<<" "<<nums[i]<<" "<<t1<<" "<<t2<<"\n";
            sum=(sum+t1+t2)%mod;
        }
         return (int)(sum)%mod;
    }
   
};
```
['C++']