P2168,55分,求助
  • 板块灌水区
  • 楼主dldltangmen
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/7/12 15:22
  • 上次更新2024/7/12 16:09:11
查看原帖
P2168,55分,求助
1147190
dldltangmen楼主2024/7/12 15:22
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<algorithm>
#define ll long long
using namespace std;
ll a[100005],ans;
ll n,k;
struct node{
	ll x,y;
};
struct cmp{
	bool operator () (const node &x,const node &y) const
	{
		return x.x>y.x;
	}
};
priority_queue<node,vector<node>,cmp>q;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		q.push({a[i],0}); 
	}
	ll pos=(n-1)%(k-1); 
	if(pos!=0){
		ll cnt=0,maxx=0;
		for(int i=1;i<=pos+1;i++){
			cnt+=q.top().x;
			maxx=max(maxx,q.top().y);
			q.pop();
		}
		q.push({cnt,maxx+1});
		ans+=cnt;
	}
	while(q.size()!=1){
		ll cnt=0,maxx=0;
		for(int i=1;i<=k;i++){
			cnt+=q.top().x;
			maxx=max(maxx,q.top().y);
			q.pop();
		}
		q.push({cnt,maxx+1});
		ans+=cnt;
	}
	cout<<ans<<endl<<q.top().y;
	return 0;
}
2024/7/12 15:22
加载中...