#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
register int x=0,f=0;register char c=getchar();
while(c<'0'||c>'9')f=(c=='-'),c=getchar();
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c&15),c=getchar();
return f?-x:x;
}
int n,k;
struct node{
int num,deep;
};
bool operator<(node x,node y){
if(x.num!=y.num)return x.num>y.num;
else return x.deep>y.deep;
}
priority_queue <node> q;
signed main(){
n=read();k=read();
for(int i=1;i<=n;i++){
int x=read();
q.push({x,1});
}
for(int i=n;(i-1)%(k-1)!=0;i++)q.push({0,1});
int ma=0,ans=0;
while(q.size()!=1){
int sum=0;
for(int i=1;i<=k;i++){
node tmp=q.top();q.pop();
ma=max(ma,tmp.deep);
sum+=tmp.num;
}
ans+=sum;
q.push({sum,ma+1});
}
cout<<ans<<"\n"<<ma<<'\n';
return 0;
}
04-25
2150
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-07
1345
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)