#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin >> N >> K; priority_queue,greater<>> Q; long long answer = 0,now = 0; vector A(K); for(auto &a : A) cin >> a; for(int i=K-1; i>=0; i--){ now += A.at(i)*(i+1); if(i < K-1) A.at(i) += A.at(i+1); if(i) Q.push(A.at(i)); } answer = now; long long zero = 0; for(int i=K; i> a; now += a*K; if(Q.size()) now += zero-Q.top(),Q.pop(); answer = max(answer,now); if(K > 1) Q.push(zero),zero -= a; } cout << answer << endl; }