比赛 |
ZLXSCDay1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
PERICA |
最终得分 |
100 |
用户昵称 |
Zayin |
运行时间 |
0.319 s |
代码语言 |
C++ |
内存使用 |
1.85 MiB |
提交时间 |
2016-03-18 19:30:34 |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 100500
#define modu 1000000007LL
using namespace std;
typedef long long LL;
int n,k;
LL ans,a[maxn],c[maxn];
void gcd(LL a,LL b,LL &x,LL &y)
{
if (!b)
{
x=1,y=0;
} else
{
gcd(b,a%b,y,x);
y-=(a/b)*x;
}
}
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]);
sort(a+1,a+n+1);
--k;
c[k]=1;
for (int i=k+1;i<=n;++i)
gcd((LL)(i-k),modu,c[i],c[0]),
// cout<<i<<" "<<c[i]<<" "<<(LL)(i-k)<<" "<<c[i]<<" "<<modu<<" "<<c[0]<<endl,
c[i]=( (c[i]*c[i-1]) % modu *i) % modu,
c[i]=( c[i]+ modu ) % modu;
// for (int i=k;i<=n;++i) cout<<c[i]<<endl;
for (int i=n;i>=k;--i)
ans+=(a[i]*c[i-1]) % modu,
ans%=modu;
cout<<ans<<endl;
return 0;
}