//对此我本不想说什么,太简单了,就是个简单的优先队列的思维就可以了
//我发现大多数人竟是一同乱搞,真的很无语
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
priority_queue<int, vector<int>, greater<int> >g;
int main() {
int T,n,x;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d",&x);
g.push(x);
}
int res=0;
while(true) {
int x1=g.top();
g.pop();
int x2=g.top();
g.pop();
res+=x1+x2;
if(g.empty())break;
g.push(x1+x2);
}
printf("%d\n",res);
}
return 0;
}
合并果子,优先队列的使用
最新推荐文章于 2025-06-18 23:15:45 发布