#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef long long ll;
typedef pair<ll,int> PII;
int n,k;
int main()
{
cin>>n>>k;
ll x;
priority_queue<PII,vector<PII>,greater<PII> > q;
for(int i=1;i<=n;i++)
{
cin>>x;
q.push({x,0});
}
while((n-1)%(k-1)!=0) q.push({0,0}),n++;
ll res=0;
int depth=0;
while(q.size()>1)
{
ll s=0;
for(int i=0;i<k;i++ )
{
auto t=q.top();
q.pop();
s+=t.x;
depth=max(depth,t.y);
}
res+=s; q.push({s,depth+1});
}
cout<<res<<endl<<q.top().y<<endl;
}