板块漂移
p2168
55分
#include <iostream>
#include <queue>
#include <cmath>
#define int long long
using namespace std;
int w[100010];
struct zf{
int w;
int h;
};
bool operator<(zf x, zf y){
return x.w > y.w;
}
priority_queue<zf> q;
signed main(){
int n, k;
cin >> n >> k;
for(int i=1;i<=n;i++){
cin >> w[i];
q.push({w[i], 0});
}
while((q.size()-1)%(k-1)!=0)q.push({0, 0});
int ans=0,bh=0;
while(q.size() > 1){
int he=0;
int h=0;
for(int i=1;i<=k;i++){
he += q.top().w;
h = max(h, q.top().h + 1);
q.pop();
}
q.push({he, h});
ans += he;
bh = max(bh, h);
}
printf("%lld\n%lld", ans, bh);
return 0;
}