比赛 ZLXSCDay1 评测结果 AAAAAAAAAA
题目名称 PERICA 最终得分 100
用户昵称 dashgua 运行时间 0.238 s
代码语言 C++ 内存使用 21.68 MiB
提交时间 2016-03-18 21:44:42
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>

const int maxn = 100005, maxk = 55;
const int mod = 1000000007;

int n, k, a[maxn];
int c[maxn][maxk];

int main()
{
	freopen("perica.in","r",stdin);
	freopen("perica.out","w",stdout);
	
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	
	std::sort(a + 1, a + n + 1);
	
	c[0][0] = 1;
	for(int i = 1; i <= n; i++)
	{
		c[i][0] = 1;
		
		for(int j = 1; j <= i && j <= k; j++)
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
	}
	
	int ans = 0;
	
	for(int i = 1; i <= n; i++)
		(ans += 1LL * c[i - 1][k - 1] * a[i] % mod) %= mod;
	
	printf("%d", ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}