求助(悬关)
  • 板块灌水区
  • 楼主Ethan_tang
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/20 19:43
  • 上次更新2024/11/20 21:14:08
查看原帖
求助(悬关)
1491661
Ethan_tang楼主2024/11/20 19:43

P2168,0pts,全WA

#include <bits/stdc++.h>
using namespace std;
struct tree
{
	long num;
	long h;
	bool operator< (const tree &x)
	const
	{
		if(num != x.num) return num > x.num;
        return h > x.h;	
	}
};
tree pos(int num1,int h1)
{
	tree w;
	w.num = num1;
	w.h = h1;
	return w;
}
long n,k,ans1 = 0,ans2 = 0;
priority_queue <tree> q;
int main()
{
	cin >> n >> k;
	if ((n-1) % (k-1))
	{
		for (int i = 0;i < (n-1) % (k-1) + 1;i++)
		{
			q.push(pos(0,0));	
		}
	}
	for (int i = 0;i < n;i++)
	{
		int x;
		cin >> x;
		q.push(pos(x,1));	
	}
	while (q.size() == 1)
	{
		long he = 0,maxn = -1e6;
		for (int i = 0;i < k;i++)
		{
			he += q.top().num;
			maxn = max(q.top().h,maxn);
			q.pop();
		}
		q.push(pos(he,maxn));
		ans1 += he;
        ans2 = max(maxn,ans2);
	}
	cout << ans1 << endl << ans2;
	return 0;
}
2024/11/20 19:43
加载中...