0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 18:12:04 +00:00
OI-codes/S2OJ/1970/data/std.cpp

47 lines
1.1 KiB (Stored with Git LFS)
C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define templ template<typename T>
templ bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
#ifdef NTFOrz
freopen("a.in","r",stdin);
#endif
}
typedef long long ll;
#define mod 1000000007ll
#define sz 101010
int n,m;
int a[sz];
ll pw[sz];
ll SS(ll n){return n*(n-1)/2%mod;}
int main() {
cin>>n>>m;
ll S=0;
rep(i,1,n) cin>>a[i],(S+=a[i])%=mod;
pw[0]=1; rep(i,1,sz-1) pw[i]=pw[i-1]*2%mod;
ll ans=0;
rep(i,1,m) {
ll sum=S*pw[i-1]%mod;
ll W=sum*(n*pw[i]%mod+1)%mod;
sum=sum*2%mod;
ll res=W*pw[m-i]%mod+sum*SS(pw[m-i])%mod*pw[i]%mod*n%mod;
chkmax(ans,res%mod);
}
ll sum=S;
ll W=0; rep(i,1,n) (W+=1ll*a[i]*(n-i+1)%mod)%=mod;
ll res=W*pw[m]%mod+sum*SS(pw[m])%mod*n%mod;
chkmax(ans,res%mod);
cout<<ans;
return 0;
}