Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (79 sloc) 1.4 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
#ifdef LOCAL
freopen("891E.txt","r",stdin);
#endif
buf[fread(buf,1,MAXSIZE,stdin)]='\0';
bufpos=0;
}
#if NEG
int readint(){
bool isneg;
int val=0;
for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
bufpos+=(isneg=buf[bufpos]=='-');
for(;isdigit(buf[bufpos]);bufpos++)
val=val*10+buf[bufpos]-'0';
return isneg?-val:val;
}
#else
int readint(){
int val=0;
for(;!isdigit(buf[bufpos]);bufpos++);
for(;isdigit(buf[bufpos]);bufpos++)
val=val*10+buf[bufpos]-'0';
return val;
}
#endif
char readchar(){
for(;isspace(buf[bufpos]);bufpos++);
return buf[bufpos++];
}
int readstr(char* s){
int cur=0;
for(;isspace(buf[bufpos]);bufpos++);
for(;!isspace(buf[bufpos]);bufpos++)
s[cur++]=buf[bufpos];
s[cur]='\0';
return cur;
}
const int mod=1000000007;
ll a[5003];
ll power(ll x,ll y){
ll ans=1;
while(y){
if (y&1)
ans=ans*x%mod;
x=x*x%mod;
y>>=1;
}
return ans;
}
int main(){
init();
int n=readint();
ll k=readint(),ans=1;
a[0]=1;
for(int i=1;i<=n;i++){
ll x=readint();
ans=ans*x%mod;
for(int j=i-1;j>=0;j--){
a[j+1]=(a[j+1]-a[j])%mod;
a[j]=a[j]*x%mod;
}
}
ll now=1,pw=1;
ll inv=power(n,mod-2);
for(int i=0;i<=n;i++){
ans=(ans-now*pw%mod*a[i])%mod;
now=now*(k-i)%mod;
pw=pw*inv%mod;
}
printf("%lld",(ans%mod+mod)%mod);
}