五分求调
查看原帖
五分求调
710862
thrX楼主2024/1/27 10:48
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
int ans;
struct node{
	int freq,h;
	bool operator < (const node &y) const{
		return freq==y.freq?h>y.h:freq>y.freq;
	}
};
priority_queue<node> q;
signed main(){
	
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		q.push((node){t,1});
	}
	while((n-1)%(k-1)!=0)n++,q.push((node){0,1});
	while(q.size()>=k){
		int cnt=0;
		int hh=-1;
		for(int i=0;i<k;i++)hh=max(hh,q.top().h);
		for(int i=0;i<k;i++){
			cnt+=q.top().freq;
			q.pop();
		}
		ans+=cnt;
		q.push((node){cnt,hh+1});
	}
//	for(int i=1;i<=n;i++){
//		ans+=sum[i]*(q.top().h-i);
////		cout<<i<<' '<<sum[i]<<'\n';
//	}
	cout<<ans<<'\n'<<q.top().h-1<<'\n';
	
	return 0;
}
2024/1/27 10:48
加载中...