这要构建一个什么玩意
K进制haffum树
然后节点数不够咋办
加空节点‘
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
int n,k;
struct wo{
int h;
int l;
friend bool operator < (const wo x,const wo y){
if(x.l==y.l) return x.h>y.h;
return x.l>y.l;
}
};
priority_queue<wo> q;
int x,xx;
int cnt;
int ans;
int len;
signed main(){
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;++i){
scanf("%lld",&x);
q.push((wo){
1,x
});
}
if((n-1)%(k-1)!=0)
xx=(k-1)-(n-1)%(k-1);
for(int i=1;i<=xx;++i){
q.push((wo){
1,0
});
}
cnt=xx+n;
while(cnt>1){
int th=0;
int ts=0;
for(int i=1;i<=k;++i){
wo tem=q.top();
q.pop();
th=max(th,tem.h);
ts+=tem.l;
}
q.push((wo){
th+1,ts});
ans+=ts;
cnt-=(k-1);
}
printf("%lld
%lld",ans,q.top().h-1);
return 0;
}