#include<bits/stdc++.h> #define MAXN 100005 #define int long long usingnamespace std; inlineintread(){ int x=0,f=1; char ch=getchar(); while (ch<'0'||ch>'9'){ if (ch=='-') f=-1; ch=getchar(); } while (ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^'0'); ch=getchar(); } return x*f; } int a[MAXN]; structnode{ longlong val,dep; }; inlinebooloperator < (const node &A,const node &B){ if (A.val!=B.val) return A.val>B.val; elsereturn A.dep>B.dep; } #undef int intmain(){ #define int long long int n=read(),k=read(); for (registerint i=1;i<=n;++i){ a[i]=read(); } priority_queue<node>Q; for (registerint i=1;i<=n;++i){ Q.push(node{a[i],0}); } longlong ret=0; int fri=0; int tempn=n; while (true){ if (tempn>=k){tempn-=k,tempn++;} else{fri=tempn;break;} if (tempn==1){fri=k;break;} } while (true){ int max_dep=0,sz=Q.size(); longlong sum=0; int bound=0; if (fri) bound=fri,fri=0; else bound=k; for (registerint i=1;i<=bound;++i){ node t=Q.top();Q.pop(); max_dep=max(max_dep,t.dep); sum+=t.val; } ret+=sum; Q.push(node{sum,max_dep+1}); if (Q.size()==1) break; } node ans=Q.top(); printf("%lld\n%lld\n",ret,ans.dep); }