RT
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e4;
struct node{
LL val,dep;
bool friend operator<(const node &p,const node &q){
return p.val>q.val;
}
};
priority_queue<node> q;
LL n,k,ans;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){
node x;
x.dep=0;
cin>>x.val;
q.push(x);
}
if(k>2&&(n-1)%(k-1)!=0){
while(n%(k-1)!=1){
n++,q.push((node){0,0});
}
}
while(q.size()>1){
LL sum=0,maxh=0;
for(int j=1;j<=k;j++){
node x=q.top();
q.pop();
sum+=x.val;
maxh=max(maxh,x.dep);
}
ans+=sum;
q.push((node){sum,maxh+1});
}
cout<<ans<<"\n"<<q.top().dep;
}