@[wsxbm](/user/574857) 你的优先队列叫 `hb` 但是定义了一个 `int h` 并且后面也写 `h.xxx`
by rxjdasiwzl @ 2022-04-03 16:41:59
大佬,为什么我改完了之后变成了RE???
by wsxbm @ 2022-04-03 17:03:13
@[wsxbm](/user/574857) 第二个循环中 <=n应改为<n
by Southern_Dynasty @ 2022-04-03 17:34:40
@[wsxbm](/user/574857) <=n会出现 $hb$ 为空但仍然$top(),pop()$ 的情况
by Southern_Dynasty @ 2022-04-03 17:36:27
说不定我的代码会对你有帮助
```cpp
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> PQ;
int n,a[1000005] , ans;
int main() {
cin>> n ;
for(int i = 1 ; i <= n ; i++){
cin>>a[i];
PQ.push(-a[i]);
}
while(PQ.size() != 1){
int x=PQ.top();
PQ.pop();
int y=PQ.top();
PQ.pop();
ans+=x + y;
PQ.push(x+y);
}
cout<<-ans;
return 0;
}
```
by CZCCZC @ 2022-04-03 21:24:49