kotlin
IntuitionApproachComplexity
Time complexity:

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

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

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

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

# Code
```kotlin []
class Solution {
    fun minMaxSums(nums: IntArray, k: Int): Int {
        val MOD = 1_000_000_007

        val n = nums.size

        val dp = Array(n + 1) { IntArray(k + 1) }
        
        dp[0][0] = 1
        for (i in 1..n) {
            dp[i][0] = 1
            for (j in 1..k) {
                dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % MOD
            }
        }


        nums.sort()
        var total = 0L
        for (i in 0 until n){
            for (c in 0 until minOf(i + 1, k)){
                total += nums[i].toLong() * dp[i][c] % MOD
            }
            total = total % MOD
        }
        nums.reverse()

        for (i in 0 until n){
            for (c in 0 until minOf(i + 1, k)){
                total += nums[i].toLong() * dp[i][c] % MOD
            }
            total = total % MOD
        }
        return total.toInt()
    }
}
```
['Kotlin']