这个十分巧妙啊~
#include <bits/stdc++.h>
#define N 200005
#define LL long long
#define mod 1000000007
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
inline int qpow(int x,int y)
{
int tmp=1;
for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) tmp=1ll*tmp*x%mod;
return tmp;
}
inline int INV(int x) { return qpow(x,mod-2); }
int n,K;
int val[N],inv[N],fac[N];
inline void Initialize()
{
int i,j;
fac[0]=inv[0]=1ll;
for(i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%mod, inv[i]=INV(fac[i]);
}
inline int S(int _n,int _m)
{
int i,j,ans=0;
for(i=0;i<=_m;++i)
{
int a=inv[i];
if(i&1) a=mod-a;
ans=(ans+1ll*a*inv[_m-i]%mod*qpow(_m-i,_n)%mod)%mod;
}
return ans;
}
int main()
{
// setIO("input");
int i,j,sum=0;
scanf("%d%d",&n,&K);
for(i=1;i<=n;++i) scanf("%d",&val[i]),sum=(sum+val[i])%mod;
Initialize();
printf("%d\n",1ll*sum*(S(n,K)+1ll*(n-1)*S(n-1,K)%mod)%mod);
return 0;
}