问题描述
我正在尝试解决有关优先级队列实施的初学者问题。 https://www.hackerearth.com/practice/data-structures/trees/heapspriority-queues/practice-problems/algorithm/monk-and-the-magical-candy-bags/description/
但是我的解决方案在最后三个测试用例中失败了。伊德为什么。我也阅读了社论,但解决方案似乎与我的解决方案非常相似。有人可以帮我弄清楚我出了什么问题吗?
这是我的代码。
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define MOD 1000000007
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << "," << #y << ": " << (y) << endl; }
/* __builtin_popcount(),__builtin_popcountll() // return no. of set bits
next_permutation(v.begin(),v.end())
*/
void solve() {
int n,k;
cin >> n >> k;
ll a;
priority_queue<int> pq;
for (int i = 0; i < n; i++)
cin >> a,pq.push(a);
ll count = 0;
while (k--) {
count += pq.top();
pq.push(pq.top()/2);
pq.pop();
}
cout << count << "\n";
}
int main() {
fast;
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)