题解 | #搬水果#
搬水果
http://www.nowcoder.com/practice/e4c775b0f3ee42a4bb72c26d2e1eef8a
优先队列简单运用
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n,num;
priority_queue<int,vector<int>,greater<int> > qu;
while(cin >> n && n){
for(int i = 0;i < n;++i){
cin >> num;
qu.push(num);
}
int ans = 0;
while(1 < qu.size()){
int a = qu.top();
qu.pop();
int b = qu.top();
qu.pop();
ans += a + b;
qu.push(a + b);
}
cout << ans << endl;
}
}