代码求调
  • 板块灌水区
  • 楼主Ethan_tang
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/22 19:37
  • 上次更新2024/11/22 21:21:13
查看原帖
代码求调
1491661
Ethan_tang楼主2024/11/22 19:37

P2168 40 tps,除AC全WA

#include <bits/stdc++.h>
using namespace std;
struct tree
{
	long long num;
	long 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 long n,k,ans1 = 0,ans2 = 0;
priority_queue <tree> q;
int main()
{
	cin >> n >> k;
	for (long long i = 0;i < n;i++)
	{
		int x;
		cin >> x;
		q.push(pos(x,1));	
	}
	if ((n-1) % (k-1))
	{
		for (long long i = 0;i < k - 1 - (n-1) % (k-1);i++)
		{
			q.push(pos(0,1));	
		}
	}
	long long he = 0,maxn = -2147483647;
	while (q.size() != 1)
	{
		he = 0,maxn = -2147483647;
		for (long long i = 0;i < k;i++)
		{
			he += q.top().num;
			maxn = max(q.top().h,maxn);
			q.pop();
		}
		q.push(pos(he,maxn + 1));
		ans1 += he;
        ans2 = max(maxn,ans2);
	}
	cout << ans1 << endl << ans2;
	return 0;
}
2024/11/22 19:37
加载中...