c solution
Code

# Code
```c []
int cmp(const void*a,const void*b){
    return *(int*)a-*(int*)b;
}
int minMaxSums(int* nums, int numsSize, int k) {
    qsort(nums,numsSize,sizeof(int),cmp); //做 sort - small -> large
    int mod = 1e9+7;
    // combination 存取各種組合的數值 
    int **combination = malloc(sizeof(int*)*(numsSize+1));
    for(int i=0;i<numsSize+1;i++){
        combination[i] = calloc(k+1,sizeof(int)); 
    }
    // C{n}{r} 的 table
    combination[0][0]=1;
    for(int r=1;r<numsSize+1;r++){
        combination[r][0] = 1;
        for(int c=1;c<k+1;c++){
            combination[r][c] = (combination[r-1][c-1] + combination[r-1][c]) % mod;
        }
    }
    int ans = 0;
    for(int i=0;i<numsSize;i++){
        for(int size=1;size<=k;size++){
            
            //C{numsSize-i-1}{size-1} = 從此數字(i)的右邊數值中選出size-1的數字的各種組合 ->  代表nums[i] 是最小值
            long long min_sumup = ((long long)combination[numsSize-i-1][size-1] * (long long)nums[i])%mod; 
            //C{i}{size-1} = 從此數字(i)的左邊數值中選出size-1的數字的各種組合 ->  代表nums[i] 是最大值
            long long max_sumup = ((long long)combination[i][size-1] * (long long)nums[i])%mod;
            ans = (ans + min_sumup + max_sumup)%mod;
        }
    }
    for(int i=0;i<numsSize+1;i++){
        free(combination[i]); 
    }
    free(combination);
    return ans;
}
```
['C']