Value of subsequences - MarisaOJ: Marisa Online Judge

Value of subsequences

Time limit: 1000 ms
Memory limit: 256 MB
The value of an array $B$ is the maximum element in $B$. Given an array $A$ of $n$ integers. Find the sum of value of all subsequences of length $k$ of $A$. ### Input - The first line contains 2 integers $n, k$. - The second line contains $n$ integers $A_i$. ### Output - Print the sum, modulo $10^9+7$. ### Constraints - $1 \le k \le n \le 10^5$. ### Example Input: ``` 4 2 6 7 6 5 ``` Output: ``` 39 ```