432 传统题

[ABC151E] 极差和计数 (Max-Min Sums)

时间限制
2000ms
内存限制
1024MiB
登顶 / 尝试
0/ 0
难度
4
    上传者 标签AtCoderABC151提高-组合计数贡献法

[ABC151E] 极差和计数 (Max-Min Sums)

Score : 500 points Problem Statement For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7). Constraints 1 \leq N \leq 10^5 1 \leq K \leq N |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7).