#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int n,k,tail,m;
long long w[N],hl,hr,ln,rn,sum,ans;
vector <int> ls;
struct Node{
vector <int> son;
int val,rt;
bool operator > (const Node& b) const&{
return val>b.val;
}
}tr[N];
priority_queue <Node , vector <Node> , greater<Node> > q;
void add(){
while(q.size()>=k){
vector <int> so;
sum=0;
for(int i = 0 ; i<k ; i++){
sum+=q.top().val;
so.push_back(q.top().rt);
q.pop();
}
tail+=1;
tr[tail]={so,sum,tail};
q.push(tr[tail]);
}
}
long long cal(int x,int lth){
if(x==0) return 0;
ans=max(ans,(long long)lth);
long long ret=0;
int len = tr[x].son.size();
if(len==0){
ret=tr[x].val*lth;
return ret;
}
for(int i = 0 ; i<len ; i++){
ret+=cal(tr[x].son[i],lth+1);
}
return ret;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>k;
for(int i = 1 ; i<=n ; i++){
cin>>w[i];
tr[i]={ls,w[i],i};
q.push(tr[i]);
}
tail=n,m=k-1;
while((tail-1)%m!=0){
++tail;
tr[tail]={ls,0,tail};
q.push(tr[tail]);
}
add();
cout<<cal(tail,0)<<endl;
cout<<ans;
return 0;
}