Easy || C++
Code

# Code
```cpp []
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MOD = 1e9 + 7;
const int mxN = 1e5 + 9;
const int M = 109;

class Solution {
private:
    // Modular exponentiation
    long long binexp(long long a, long long b, const long long mod) {
        long long res = 1;
        a %= mod;
        while (b) {
            if (b & 1) res = (res * a) % mod;
            a = (a * a) % mod;
            b >>= 1;
        }
        return res;
    }

    // Modular addition
    long long modadd(long long a, long long b) {
        return ((a % MOD) + (b % MOD)) % MOD;
    }

    // Modular multiplication
    long long modmul(long long a, long long b) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }

public:
    int minMaxSums(vector<int>& nums, int k) {
        int n = nums.size();
        vector<vector<long long>> c(n + 1, vector<long long>(k + 1, 0));
        
        // Initialize combinations
        for (int i = 0; i <= n; i++) {
            c[i][0] = 1;
            if (i <= k) c[i][i] = 1;
        }
        
        // Compute combinations
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= min(k, i-1); j++) {
                c[i][j] = modadd(c[i-1][j], c[i-1][j-1]);
            }
        }
        
        long long ans = 0;
        
        // Minimum sum calculation
        sort(nums.begin(), nums.end());
        int m = n - 1;
        for (int i = 0; i < n; i++) {
            long long s = nums[i];
            long long p = 0;
            for (int j = 0; j < k && j <= m; j++) {
                p = modadd(p, c[m][j]);
            }   
            ans = modadd(ans, modmul(p, s));
            m--;
        }
        
        // Maximum sum calculation
        reverse(nums.begin(), nums.end());
        m = n - 1;
        for (int i = 0; i < n; i++) {
            long long s = nums[i];
            long long p = 0;
            for (int j = 0; j < k && j <= m; j++) {
                p = modadd(p, c[m][j]);
            }   
            ans = modadd(ans, modmul(p, s));
            m--;
        }

        return ans;
    }
};


```
['Array', 'Math', 'Sorting', 'Combinatorics', 'C++']